How to deploy war file in tomcat

What is a WAR file
A WAR file stands for Web Application Archive and is a bundle for distributing or hosting a java web application. It is used as a bundle of files required by the web application that is written in Java programming language.

A war file may contain following file types:

  • Application code in the form of class files
  • Servlets(which are also class files),
  • JSPs,
  • Application’s deployment descriptor(web.xml),
  • JAR files required by the application class files,
  • Static files such as images and html files etc.

A war file needs to be deployed in a web server or an application server so that the application can be accessed over the browser.
This article will guide you how to deploy a WAR file in tomcat using different methods.
Deploy WAR in tomcat
There are following three ways to deploy a WAR file in tomcat. They are:
1. Placing WAR file in the deployment folder
Tomcat application server has a deployment directory where it places all the application WAR files. The location of this directory is <Tomcat installation folder>/webapps.
Copy your application WAR file and place it in the above mentioned location. Restart tomcat and it will extract the WAR in the same folder and hence deploy the WAR.
Thus, after WAR is deployed, the deployment folder shall contain a WAR file and its extracted version.
Tomcat uses a variable $CATALINA_BASE to refer to its root installation folder. Thus, webapps folder can also be referred as $CATALINA_BASE/webapps.

2. Placing extracted WAR in deployment folder
This method is similar to the above method but in this method, you need to place the extracted version of the WAR in $CATALINA_BASE/webapps folder.
Application will be deployed when tomcat is restarted.
3. Using tomcat manager
Tomcat provides a manager application which can be used to deploy a WAR. This application also provides a User Interface so that you can deploy the WAR interactively.
Launch tomcat console by opening the browser and navigating to URL at which tomcat is running.
Example, http://localhost:8080. This will open the below depicted page.
tomcat home page
Click the Manager App button(highlighted) and it will open a new page where you can upload your application WAR file by selecting it manually using WAR file to deploy option as shown below(highlighted).

tomcat deployment manager
Choose the file and click Deploy button.
This approach has the advantage that you do not need to restart tomcat server. It will deploy the WAR automatically after upload.
Hit the clap below if you liked this post.

sdasdasd

Leave a Reply