Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explode an EAR file

My JSF Project is deployed as an EAR file. It includes some war files also. I need an exploded version of the EAR (including exploded inner WARs).

Is there any tool to do it?

like image 611
Tony Avatar asked Feb 20 '23 19:02

Tony


2 Answers

Programmatically, or manually? EAR and WAR files, like JAR files, are really just ZIP files with a known internal file/folder structure. That means you can extract EARs and WARs like any other ZIP file, with code or with a desktop application.


Command line tool for windows would be great.

  • A Java implementation that you could drop into an executable JAR very easily: https://stackoverflow.com/a/7108813/139010
  • A bash script: https://unix.stackexchange.com/a/4372/4515
  • And finally, if you don't mind using 7zip, a Windows-compatible script: https://superuser.com/a/248349/9232
like image 61
Matt Ball Avatar answered Feb 23 '23 10:02

Matt Ball


Matt's answer was helpful, but sometimes it's nice to have it written out for you.

Here is a shell script that I wrote to solve this problem that I actually ran in Cygwin but would likely work in Linux also. It will unzip and wars, ears, or jars and keep unzipping them until recursively until none are left. You may want to then use "diff -r ear1.ear-contents ear2.ear-contents" on the resulting directories to compare two ear files.

#!/bin/sh

rm -rf ${1}-contents
mkdir ${1}-contents

echo "Unpacking ${1} to ${1}-contents"
unzip -d ${1}-contents ${1}

cd ${1}-contents

FILES_TO_PROCESS=`find . -type f \( -name "*.ear" -or -name "*.war" -or -name "*.jar" \)`

until [ "$FILES_TO_PROCESS" == "" ] ; do

    for myFile in $FILES_TO_PROCESS ; do

        mkdir ${myFile}-contents
        echo "Unpacking ${myFile} to ${myFile}-contents"
        unzip -d ${myFile}-contents ${myFile}
        rm $myFile

    done


    FILES_TO_PROCESS=`find . -type f \( -name "*.ear" -or -name "*.war" -or -name "*.jar" \)`
    echo "recursing to process files: $FILES_TO_PROCESS"
done
like image 21
Jared Avatar answered Feb 23 '23 09:02

Jared