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?
- 2,297
- 7
- 28
- 54
- 2,731
- 9
- 32
- 45
-
What will you do with the files inside the war file? – Thorbjørn Ravn Andersen Oct 24 '11 at 22:47
8 Answers
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
- 5
- 4
- 9,370
- 4
- 29
- 32
-
I used this command and extrated .war file.. but all these goes to bin folder.. can u paste the command for choosing extracting location – Gnanam R Jan 07 '14 at 08:27
-
http://stackoverflow.com/questions/15830952/extracting-jar-to-specified-directory – iltaf khalid Jan 09 '14 at 10:48
-
2
If you look at the JarFile API you'll see that it's a subclass of the ZipFile class.
The jar-specific classes mostly just add jar-specific functionality, like direct support for manifest file attributes and so on.
It's OOP "in action"; since jar files are zip files, the jar classes can use zip functionality and provide additional utility.
- 156,572
- 25
- 250
- 300
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
- 569
- 8
- 26
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.
- 467
- 9
- 19
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.
- 2,649
- 1
- 13
- 18