Tuesday, November 25, 2014

How to extract *.propertes, *.xml, *.java etc from zip/war/ear without deflating jar

We often need to deflate the jars to check some property, xml or other content files that are a part of a jar or  any archive files.
We can use jar command to extract any specific file out of a jar file


    jar -xvf abc.jar myclass.java

But the above command will extract only one file per command.

But if we want to extract all the property files or cllass files like *.class or *.properties then it will not work.

For that use this utility: unzip command prompt

Usage :
  • Download the unxip.exe
  • Add it to classpath

unzip -jo MyZipFilw.zip *.xml -d XML

It will extract all the xml files to a new folder created called XML.

If there are multiple archive file (zip/jar etc) you can create a list of them with absolute path and pass it as argument like :

for /f%d IN (C:/Mypath/ZIPList.txt) Do unzip -jo %d *.xml XMLFolder

Content of ZIPList.txt


<path to zip>/a.zip

<path to zip>/b.zip

.....