A war (web archive) A web project’s files are contained in this file. It may contain files such as servlet, xml, jsp, image, html, css, and js. Here, we’ll go through what a war file is, how to make one, how to deploy one, and how to remove one.
What is WAR File?
The WAR file (Web Application Resource or Web Application ARchive) is a container for JAR files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static sites (HTML and associated files), and other resources that make up an online application. A file entitled web.xml is located in the /WEB-INF directory of the WAR file, and it describes the structure of the online application. The web.xml file isn’t technically essential if the online application is only providing JSP files. If the online apps utilize servlets, the servlet container looks at web.xml to figure out which servlet a URL request should go to.
Advantages
- Web applications may be easily tested and deployed.
- The version of the deployed application may be easily identified.
- WAR files are supported by all Java EE containers.
- WAR files are supported by the MVC framework.
How to create a WAR File?
On the command prompt, type the following command to generate a war file:
jar -cvf project_name.war*
Here,
- -c: It is used to create a file
- -v: It is used to generate the verbose output
- -f: It is used to specify the archive filename
- *: It signifies all the files of this directory
Example – D:\apps\gfgapp>jar -cvf testapp1.war*
How to deploy the war files?
There are two ways to deploy the WAR File:
- Deploy WAR File to Tomcat – Console
- Deploy WAR File to Tomcat – Developer Portal
Steps to be followed:
- Copy the WAR file that has been updated.
- Paste the files into the designated folder.
Set up your Tomcat server to run as a service (optional), If you wish to manually deploy the war file in Apache Tomcat, navigate to the web app’s directory and paste the war file there.
How to extract the WAR Files manually?
The following is the syntax for extracting the WAR file:
jar -xvf project_name.war*
Here, -x: It is a switch of jar tool of JDK