Enterprise Java Logo

Getting Started with Tomcat - Part 1

by Dr. Wenjie He

Apache Tomcat is a very popular light-weight Java HTTP web server for Java-based web application development. It is an implementation of the Java Servlet and JavaServer Pages technologies. In this class, we are going to develop all of our web applications on Tomcat.

Apache Tomcat Versions

Servlet/JSP Spec Apache Tomcat version
2.5/2.1 6.0.18
2.4/2.0 5.5.26
2.3/1.2 4.1.37
2.2/1.1 3.3.2

Preparing for Software Installation

In this class, we are going to install many software packages on our computers. In order to manage our software well, I suggest a single tree directory structure to organize all the software packages used in this class, that is, all the software packages installed for this class are in the folder C:\JavaEE. Based on the functionalities, we organize the software in the following categories:

Note: This file structure is optional. You can use whatever file structure you like. But if we use the same file structure for the whole class, it will make our life much easier for this class, especially when we develop projects in collaboration.

Installing Java SE (or JDK)

Download the current version of Java SE

I. Installing Apache Tomcat Server

Download Tomcat 

Go to the Apache Tomcat web page http://tomcat.apache.org. Before we download, we need to decide which version of Tomcat we should download. The current version of Tomcat is 6.0.18. If you go to the Tomcat 6.0.18 download page, you would see

Tomcat 6 Screen Shot

If you compare it with the Tomcat 5.5.26, you can notice the difference.

Tomcat 5 Screen Shot

The Administration Web Application is missing in the Tomcat 6, and we are going to use the administration tool to configure the rescourses in our web applications. Therefore, we should choose Tomcat 5 for this class.

Under the 5.5.26 bar, download the following two files,

Install Tomcat 

Installation of Tomcat is very simple. You simply unzip the two files downloaded above and extract them to appropriate folders. (There is a Windows Service Installer version of Tomcat that is an executable file.)

II. Setting Environment Variables for Tomcat

Before we set the environment variables, locate the JDK installation directory and the Tomcat installation directory. In this tutorial, we collect the information in the following table,

Installation Directory of JDK Installation Directory of Tomcat
C:\JavaEE\JDKs\jdk-6u10   C:\JavaEE\Servers\Tomcat\apache-tomcat-5.5.26

Set the environment variables as in the following table

Note: If your installation directory of JDK or Tomcat is different from ours listed in the table above, you should change the values accordingly in the following table.

Variable Name Variable Value
JAVA_HOME C:\JavaEE\JDKs\jdk-6u10
CATALINA_BASE C:\JavaEE\Servers\Tomcat\apache-tomcat-5.5.26
CATALINA_HOME C:\JavaEE\Servers\Tomcat\apache-tomcat-5.5.26
CATALINA_TMPDIR C:\JavaEE\Servers\Tomcat\apache-tomcat-5.5.26\temp

  1. In your Window, click StartControl Panel. In the Control Panel window, double-click the System icon and select the Advanced tab.
  2. Click the Environment Variables button, the window of the Environment Variables opens.
  3. System Properties Window       Environment Variables Window

  4. Click the New button in the top half, and type JAVA_HOME as the variable name and C:\JavaEE\JDKs\jdk-6u10 as the variable value. Click OK.
  5. Windows Vista Users:

    You should set JAVA_HOME at the System variables area, the bottom half of the Environment Variables window. Otherwise, it would not work.

  6. Similarly, set the other environment variables in the table. Watch the video clip (play Play Button) for more detail.

Question: After you set the environment variables, do you need to restart the computer to make the change take effect?

III. Running Tomcat

IV. Running Web Application in Tomcat

Get the example

Download the example Duke.zip. After you unzip it, you get the Duke folder. This example is from the Sun's Java EE 5 Tutorial. You can find the example by

Deploy the example in Tomcat

You simply copy the Duke folder into the folder C:\JavaEE\Servers\Tomcat\apache-tomcat-5.5.26\webapps.

Run the example

Duke Page 1 Duke Page 2

Watch the video clip (play Run web application in Tomcat) for the whole procedure.

V. Running Tomcat on School Machines

Many students use the school machines to work on their Java EE projects, and they do not have the privilege to set the environment variables on the school machines. In this situation, we can use a .bat script to set the environment variables as follows.

==========The End==========