Open In App

Servlet – War File

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

  1. Web applications may be easily tested and deployed.
  2. The version of the deployed application may be easily identified.
  3. WAR files are supported by all Java EE containers.
  4. 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,



Example – D:\apps\gfgapp>jar -cvf testapp1.war*

How to deploy the war files?

There are two ways to deploy the WAR File:

Steps to be followed:

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

Article Tags :