Extracting a WAR File in Linux

WAR (Web ARchive) files are compressed archives used to package Java web applications for deployment. Since WAR files are essentially ZIP archives with a .war extension, they can be extracted using standard Linux command-line tools. This article demonstrates how to extract WAR files on Linux using two primary methods.

A WAR file contains all components needed for a web application, including HTML pages, CSS stylesheets, JavaScript files, Java classes, configuration files, and libraries. Extracting these files allows developers to inspect, modify, or troubleshoot web applications.

Prerequisites

Before extracting WAR files, ensure you have the following tools installed

  • A Linux system with command-line access

  • The jar command (part of OpenJDK package)

  • The unzip utility

Install these tools using your distribution's package manager

# On Ubuntu/Debian
sudo apt update
sudo apt install openjdk-8-jdk unzip

# On CentOS/RHEL
sudo yum install java-1.8.0-openjdk unzip

# On Fedora
sudo dnf install java-1.8.0-openjdk unzip

Method 1 Using the jar Command

The jar command is specifically designed for Java archive manipulation and provides native support for WAR files.

Basic Extraction

Navigate to the directory containing your WAR file and extract it

cd /path/to/directory
jar xf mywebapp.war

The x flag extracts files, while f specifies the archive filename. This creates a directory structure in the current location.

Extract to Specific Directory

To extract contents to a designated directory

mkdir /opt/extracted-app
jar xf mywebapp.war -C /opt/extracted-app

Verbose Extraction

Use the v flag to see extraction progress

jar xvf mywebapp.war

Method 2 Using the unzip Command

Since WAR files are ZIP archives, the unzip command works seamlessly for extraction.

Basic Extraction

unzip mywebapp.war

Extract to Specific Directory

unzip mywebapp.war -d /opt/extracted-app

List Contents Without Extraction

To preview WAR file contents without extracting

unzip -l mywebapp.war

Comparison of Methods

Feature jar Command unzip Command
Purpose Java-specific tool General ZIP utility
Syntax Simplicity Moderate Simple
Performance Optimized for Java archives General-purpose performance
Additional Features Manifest handling, signing Advanced filtering, compression options
Availability Requires JDK installation Standard on most Linux systems

Example Typical WAR File Structure

After extraction, a typical WAR file structure looks like this

mywebapp/
??? WEB-INF/
?   ??? web.xml
?   ??? classes/
?   ??? lib/
??? META-INF/
?   ??? MANIFEST.MF
??? index.html
??? css/
??? js/
??? images/

Key Points

  • Both jar and unzip commands effectively extract WAR files

  • Use jar for Java-centric environments where JDK tools are preferred

  • Use unzip for general-purpose extraction or when JDK is not available

  • WAR files may contain sensitive configuration data handle securely

  • Extracted files retain their original directory structure and permissions

Conclusion

Extracting WAR files on Linux is straightforward using either the jar or unzip command. The jar command is ideal for Java development environments, while unzip offers simplicity and universal availability. Both methods preserve the complete directory structure and file permissions of the original web application.

Updated on: 2026-03-17T09:01:38+05:30

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements