Tomcat is a very popular web server/servlet container that can host Java web applications which are made up of servlets, JSP pages (dynamic content), HTML pages, javascript, stylesheets, images… (static content).                     

This article describes the most common ways about how to deploy a Java web application on Tomcat, include the followings:

Suppose you have Tomcat installed on your development computer and have read/write permission on Tomcat’s installation directory.

Table of content:

 

What you need to know before begin

While working with deployment of Java web applications on Tomcat, you should prepare yourself with a strong grasp about the following stuff:

 

The following picture depicts what we have said so far:

directory layout

 

Deploy method #1: copying Java web application archive file (.war)

In this method, the web application is packed as a WAR file. You may generate the WAR file using a tool or IDE like Eclipse, or someone just sent you the file.

NOTE: Later if you want to update changes for the application, you must both replace the WAR file and delete the application’s unpacked directory, and then restart Tomcat.



 

Deploy method #2: copying unpacked Java web application directory

In this method, you have the web application in its unpacked form.

NOTE: If you want to update changes for the application, you must replace the corresponding files under its document root directory.

 

Deploy method #3: using Tomcat’s manager application

In this method, you can deploy the web application remotely via a web interface provided by Tomcat’s manager application. You must have user name and password to access this application. The manager application is installed by default, but not always. So be sure that it is installed with your version of Tomcat.

Using the manager application, you can:

By default, the manager application is deployed under context /manager, so to access it, type the following URL into your web browser’s address bar (the port number may vary, depending on your server’s configuration):

http://localhost:8080/manager

After supplying correct user name and password, you get into the following screen:

tomcat manager application

The list of deployed applications is shown at the top, scroll down a little bit to see the deployment section:

deployment section

As we can see, there are two ways for deploying a web application using the manager:

The former way is only suitable if the application’s WAR file or directory resides on the server and we have to know the URL. The latter way is easier in which we can pick up a WAR file and upload it to the server.

Click Browse button to pick up a WAR file and click Deploy button. For example we select StrutsFileUploader.warfile. As soon as the WAR file is uploaded to the server, it is unpacked into $CATALINA_HOME\webapps directory. The manager adds the newly deployed application to the list of applications:

newly deployed app

The newly deployed application – StrutsFileUploader, is up and running, without the need of restarting the server.

 

Access the deployed Java web application

Typically, a web application can be accessed by typing its context path follows the server’s IP/domain (including port number if any). For example, the StrutsFileUploader application above can be accessed in web browser by typing:

http://localhost:8080/StrutsFileUploader

Or we can access an individual application from the manager application by click on the context path (first column in the list of applications).

 

References:

                http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html

 

Other Tomcat Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.