Linux command for extracting war file?
253,508
Solution 1
Using unzip
unzip -c whatever.war META-INF/MANIFEST.MF
It will print the output in terminal.
And for extracting all the files,
unzip whatever.war
Using jar
jar xvf test.war
Note! The jar
command will extract war contents to current directory. Not to a subdirectory (like Tomcat does).
Solution 2
Or
jar xvf myproject.war
Solution 3
A war file is just a zip file with a specific directory structure. So you can use unzip or the jar tool for unzipping.
But you probably don't want to do that. If you add the war file into the webapps directory of Tomcat the Tomcat will take care of extracting/installing the war file.
Solution 4
You can use the unzip
command.
Solution 5
Extracting a specific folder (directory) within war file:
# unzip <war file> '<folder to extract/*>' -d <destination path>
unzip app##123.war 'some-dir/*' -d extracted/
You get ./extracted/some-dir/
as a result.
Related videos on Youtube
Author by
ammar
Updated on July 08, 2022Comments
-
ammar almost 2 years
How can I extract a
.war
file with Linux command prompt? -
extraneon over 13 yearsI actually think the
jar
command is better as it is designed to do just that. -
radonys over 11 yearsSometimes Tomcat won't extract the archive, and you have to do it manually. It can happen.
-
Kdeveloper over 11 yearsIn that case you might want to restart tomcat, or use the 'touch <filename>' so Tomcat starts extracting.
-
Yasin Okumuş almost 11 yearsSometimes Weblogic doesn't want to use war :)
-
nuoritoveri almost 10 years@extraneon Could you explain why
jar
is better? They both extract the folder, so why in your opinion isjar
better? I don't find It was desinged for that a valid argument. -
Kheshav Sewnundun almost 9 years@extraneon Well It depends on a particular situations: For example in terms of cpu utilization unzip is far better than jar (0.624 CPU vs 1.063 CPU utilized) cpu migration ( 0 vs 16) Performance counter stats for 'jar xvf Calendar.war': 325.095182 task-clock (msec) # 1.063 CPUs utilized 16 cpu-migrations #0.049 K/sec 3,049 page-faults #0.009 M/sec 0.305890466 seconds time elapsed * Performance counter stats for 'unzip Calendar.war': 36.900667 task-clock (msec) # 0.624 CPUs utilized 0 cpu-migrations #0.000 K/sec 419 page-faults # 0.011 M/sec 0.059182220 seconds time elapsed
-
Nithyanandhan M over 5 yearsIn unzip command, if we use '-c', it will extract files to stdout/screen (‘‘CRT’’). For extracting war file(all files) don't use flag c.
-
Erica Kane over 3 yearsIf you have a WAR file, jar already exists on your system. unzip might not.