How to Extract War File

Rupam Yadav Feb 02, 2024
  1. Steps to Extract a WAR File Using Command Line/Terminal
  2. Extract a WAR File by Renaming It
How to Extract War File

A WAR file in Java is a JAR file containing web-based components like servlets, HTML property files, resources, etc. WAR is short for Web Application Archive, a file that archives all the necessary components to efficiently transfer a file from a server to a client. In this tutorial, we will see how we can extract a generated WAR file.

Steps to Extract a WAR File Using Command Line/Terminal

  • Open the folder where the WAR file is located. It is usually in the project folder, like shown below.

    Extract war file - 1

  • Open the command line/terminal and type the command jar -xvf nameOfTheWarFile.war.

    Here in the command, the first main command item, jar, creates an archive or restores them from an archive. To extract the archived WAR file, we use the command option x that extracts the contents of the file, then to print the logs of the process on the command line/terminal, we use the v command option. The option f specifies the name of the WAR file and we write the file’s path in the last.

    Following is an example of a command prompt screen after the WAR file has been extracted. We can see that the logs specify the creation and inflation of a few files.
    Extract war file - 2

  • Now, we check the folder where we extracted the file. There will be a few files like as shown below. The WAR has been successfully extracted.

    Extract war file - 3

Extract a WAR File by Renaming It

Another quick way to extract the WAR file is to rename it and change its file extension. To do this, we first locate the file, then we change its name from theWarFile.war to theWarFile.zip. Notice that war and zip are file extensions. Now, we use a tool or functionality to extract any normal zip file.

Author: Rupam Yadav
Rupam Yadav avatar Rupam Yadav avatar

Rupam Saini is an android developer, who also works sometimes as a web developer., He likes to read books and write about various things.

LinkedIn