[java] How to extract .war files in java? ZIP vs JAR

I have a web program where I want the user to be able to import a .war file and I can extract certain files out of the .war file. I have found two class libraries: java.util.zip.* and java.util.jar.*. From what I understand, a WAR file is a special JAR file which is a special ZIP file. So would it be better to use java.util.jar? If ZIP and JAR files are pretty much the same why is there a need for two different libraries?

This question is related to java jar zip war

The answer is


You can use a turn-around and just deploy the application into tomcat server: just copy/paste under the webapps folder. Once tomcat is started, it will create a folder with the app name and you can access the contents directly


For mac users: in terminal command :

unzip yourWARfileName.war

Just rename the .war into .jar and unzip it using Winrar (or any other archive manager).


If you using Linux or Ubuntu than you can directly extract data from .war file.

A war file is just a jar file, to extract it, just issue following command using the jar program:

jar -xvf yourWARfileName.war

Like you said, a jar is a zip file (not a special type, but just a plain old zip), so either library could be made to work. The reasoning is that the average person, seeing a *.zip extension, tends to unzip it. Since the app server wants it unzipped, a simple rename keeps people from unzipping it simply out of habit. Likewise, *.war file also should remain uncompressed.

java.util.jar basically just adds additional functionality to java.util.zip with very little extra overhead. Let the java.util.jar be a helper in posting, etc... and use it.


Jar class/package is for specific Jar file mechanisms where there is a manifest that is used by the Jar files in some cases.

The Zip file class/package handles any compressed files that include Jar files, which is a type of compressed file.

The Jar classes thus extend the Zip package classes.


WAR file is just a JAR file, to extract it, just issue following jar command –

jar -xvf yourWARfileName.war

If the jar command is not found, which sometimes happens in the Windows command prompt, then specify full path i.e. in my case it is,

 c:\java\jdk-1.7.0\bin\jar -xvf my-file.war

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to jar

Running JAR file on Windows 10 Add jars to a Spark Job - spark-submit Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature) java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactory Maven Error: Could not find or load main class Where can I download mysql jdbc jar from? Access restriction: The type 'Application' is not API (restriction on required library rt.jar) Create aar file in Android Studio Checking Maven Version Creating runnable JAR with Gradle

Examples related to zip

Install php-zip on php 5.6 on Ubuntu 7-Zip command to create and extract a password-protected ZIP file on Windows? How are zlib, gzip and zip related? What do they have in common and how are they different? Read a zipped file as a pandas DataFrame Installing PHP Zip Extension How can you zip or unzip from the script using ONLY Windows' built-in capabilities? Creating a ZIP archive in memory using System.IO.Compression how to zip a folder itself using java Read Content from Files which are inside Zip file Need to ZIP an entire directory using Node.js

Examples related to war

Deploying Java webapp to Tomcat 8 running in Docker container What is WEB-INF used for in a Java EE web application? How to unpackage and repackage a WAR file How to start jenkins on different port rather than 8080 using command prompt in Windows? Update Jenkins from a war file Oracle JDBC ojdbc6 Jar as a Maven Dependency UnsupportedClassVersionError unsupported major.minor version 51.0 unable to load class How to extract .war files in java? ZIP vs JAR How do I update a Tomcat webapp without restarting the entire service? Difference between jar and war in Java