Unpacking War File on OS X and Linux

Published on March 6, 2015 by

If you have packaged a web application within a .war file, then you might want to check the contents of it for various reasons. There are a number of tools that can do this, but I am going to show you a simple command that can display the contents of the war file within the Terminal. Therefore one does not need to install any software to do this. Another command can extract the contents of the war file, which I will also show you. Please note that these commands work for UNIX-like systems such as Linux or Mac OS X. I am sure it can also be used on Windows, but I have no set it up nor tested it myself.

Show Contents of War File

First, let us see how we can display the contents of a war archive within the Terminal. It is as simple as the below command.


jar -tf example.war

Extract Contents of War File

Now, let us extract the contents of the war archive.


jar -xvf example.war

This extracts the contents of the file in the current directory, which may not be desirable. Therefore one may want to extract it in a different directory. First, let us create a temporary directory.


mkdir /tmp/extracted

The following commands copies the war file to the temporary directory, extracts it, removes the war file and lists the contents of the directory.


cd /tmp/extracted && cp /path/to/example.war /tmp/extracted/example.war && jar -xvf example.war && rm example.war && ls -al

I hope this helped you. Thank you for reading.

Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

Leave a Reply

Your e-mail address will not be published.