How can I extract a .war
file with Linux command prompt?
Asked
Active
Viewed 2.7e+01k times
6 Answers
160
-
12I actually think the `jar` command is better as it is designed to do just that. – extraneon Sep 30 '10 at 18:29
-
4@extraneon Could you explain why `jar` is better? They both extract the folder, so why in your opinion is `jar` better? I don't find *It was desinged for that* a valid argument. – nuoritoveri Jul 23 '14 at 14:59
-
4@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 – Kheshav Sewnundun Aug 25 '15 at 08:06
-
1In 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. – Nithyanandhan M Jan 30 '19 at 08:55
-
1If you have a WAR file, jar already exists on your system. unzip might not. – Erica Kane Feb 17 '21 at 17:24
9
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.

Kdeveloper
- 13,679
- 11
- 41
- 49
-
3Sometimes Tomcat won't extract the archive, and you have to do it manually. It can happen. – radonys Dec 19 '12 at 15:43
-
In that case you might want to restart tomcat, or use the 'touch
' so Tomcat starts extracting. – Kdeveloper Jan 20 '13 at 14:43 -
1
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.

Nux
- 9,276
- 5
- 59
- 72