Main Tutorials

How to unzip a WAR file in Java

In J2EE web development, Web Application Archive(WAR) file is just a normal JAR file, which consists all of your web application components like, servlets, Java classes, libraries, resources and etc. Read Wiki for detail.

Problem

Current web application WAR file is generated via Ant or Maven tool, copy to *nix environment for deployment, but no idea how to extract the WAR file?

Solution

WAR file is just a JAR file, to extract it, just issue following jar command – “jar -xvf yourWARfileName.war“.

See output…


#jar -xvf mkyongApp.war

  created: WEB-INF/
  created: WEB-INF/classes/
  created: WEB-INF/classes/META-INF/
  created: WEB-INF/classes/com/
  created: WEB-INF/classes/com/mkyong/
  ......
extracted: WEB-INF/classes/applicationContext-mail.xml
extracted: WEB-INF/classes/com/mkyong/batch/batchProcessor.class
  ......
Note
In most application server like GlassFish, JBoss or web container like Tomcat, you don’t need to extra the “WAR” file, just copy to correct folder, and it will extract by the deployed server during start up.

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
8 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ragunath
10 months ago

Does all Java version support this command?

Debasish
2 years ago

jar -xvf yourWARfileName.war“ is not working in Deployment server
war file is also not Extracted after running sudo sh catalina.sh start and aslo
sudo sh ./startup.sh

Mathu
6 years ago

Can you please provide java code to unpack war file?

Dimple Aggarwal
7 years ago

it is not working for me. It shows error ‘jar’ is not recognized as an internal command

Risman Gunawan
5 years ago

place your war file in C:\Program Files\Java\jdk1.7.0_79\bin.
in command prompt C:\Program Files\Java\jdk1.7.0_79\bin\jar -xvf my-file.war

i try it, success…

bharath sn
10 years ago

it dint unzip
jar -xvf war.zip

kanhu bhol
10 years ago

Thanks mkyong…

Sanjeev Dixit
11 years ago

In the note mentioned above, there is a spelling mistake…instead of “extra” in the first line, change it to “extract”