Wednesday, 30 September 2015

War File

War File

war (web archive) File contains files of a web project. It may have servlet, xml, jsp, image, html, css, js etc. files.
Here, we will discuss what is war file, how to create war file, how to deploy war file and how to extract war file.

What is war file?

web archive (war) file contains all the contents of a web application. It reduces the time duration for transferring file.

Advantage of war file

saves time: The war file combines all the files into a single unit. So it takes less time while transferring file from client to server.

How to create war file?

To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file.
Go inside the project directory of your project (outside the WEB-INF), then write the following command:
  1. jar -cvf projectname.war *  
Here, -c is used to create file, -v to generate the verbose output and -f to specify the arhive file name.
The * (asterisk) symbol signifies that all the files of this directory (including sub directory).

How to deploy the war file?

There are two ways to deploy the war file.
  1. By server console panel
  2. By manually having the war file in specific folder of server.
If you want to deploy the war file in apache tomcat server manually, go to the webapps directory of apache tomcat and paste the war file here.
Now, you are able to access the web project through browser.

Note: server will extract the war file internally.


How to extract war file manually?

To extract the war file, you need to use -x switch of jar tool of JDK. Let's see the command to extract the war file.
  1. jar -xvf projectname.war  

No comments:

Post a Comment