108

How can I extract a .war file with Linux command prompt?

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
ammar
  • 1,373
  • 4
  • 11
  • 13

6 Answers6

160

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).

Nux
  • 9,276
  • 5
  • 59
  • 72
jmj
  • 237,923
  • 42
  • 401
  • 438
  • 12
    I 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
  • 1
    In 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
  • 1
    If you have a WAR file, jar already exists on your system. unzip might not. – Erica Kane Feb 17 '21 at 17:24
33

Or

jar xvf myproject.war

Raghuram
  • 51,854
  • 11
  • 110
  • 122
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
2

You can use the unzip command.

tangens
  • 39,095
  • 19
  • 120
  • 139
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
0

Following command will help you.

unzip application.war -d output/