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.
- What is a war file?
- Advantages of the war file.
- How to create a war file?
- How to deploy the war file?
- 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.
- Easy testing and deployment of web applications
- It has easy identification of the version of the deployed application
- All Java EE containers support WAR files
- 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:
- Deploy WAR File to Tomcat – Console
- Deploy WAR File to Tomcat – Developer Portal
Steps to be followed:
- Copy the updated WAR File
- Paste the files into the specified location
- 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.