WAR File in Java

WAR File in Java Application

In this article, I am going to discuss WAR File in Java Application. Please read our previous article where we discussed User Interface Form Designs using Servlets. At the end of this article, you will understand the following pointers.

  1. What is a war file?
  2. Advantages of the war file.
  3. How to create a war file?
  4. How to deploy the war file?
  5. How to extract the war file manually?
What is WAR File?

The WAR file (Web Application Resource or Web application ARchive) is a file used to distribute a collection of JAR-files, JavaServer Pages, Java Servlets, Java classes, XML files, tag libraries, static sites (HTML and related files), and other resources that together constitute an internet application. The /WEB-INF directory within the WAR file contains a file named web.xml which defines the structure of the online application. If the online application is merely serving JSP files, the web.xml file isn’t strictly necessary. If the online applications are using servlets, then the servlet container uses web.xml to determine to which servlet a URL request is going to be routed.

  1. Easy testing and deployment of web applications
  2. It has easy identification of the version of the deployed application
  3. All Java EE containers support WAR files
  4. MVC structure supports WAR files.
How to create a WAR File?

To create a war file, we have to use the following command on the command prompt:
jar -cvf project_name.war*
-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\testapp>jar -cvf testapp1.war*

How to deploy the war files?

There are two ways to deploy WAR File:

  1. Deploy WAR File to Tomcat – Console
  2. Deploy WAR File to Tomcat – Developer Portal

Steps to be followed:

  1. Copy the updated WAR File
  2. Paste the files into the specified location
  3. Configure your Tomcat server as service (optional)
How to extract the WAR Files manually?

To extract the WAR File, we have the following syntax:

jar -xvf project_name.war*

Here, -x: It is a switch of jar tool of JDK

In the next article, I am going to discuss the Welcome-file-list in Java Servlet Application. Here, in this article, I try to explain WAR File in Java Application. I hope you enjoy this WAR File in Java Application article.

Leave a Reply

Your email address will not be published. Required fields are marked *