Support free tutorials:

vogella training Training Books

Apache Tomcat - Tutorial

Lars Vogel

Version 1.1


Revision History
Revision 0.1 18.11.2008 Lars
Revision 0.2-1.1 09.04.2009 - 15.11.2012 Lars
bug fixed and enhancements

Apache Tomcat

This article describes the installation and usage of Apache Tomcat for Java web development. Tomcat version 7.x is used in this tutorial.

Table of Contents

1. Apache Tomcat
2. Installation
2.1. Ubuntu Linux
2.2. Windows
3. Managing Apache Tomcat
3.1. Start Tomcat on Ubuntu (Linux)
3.2. Start Tomcat on Windows
3.3. Test Tomcat
3.4. Admin console
3.5. Deployment
4. Developing Java web applications
5. Tomcat as HTTP Server
6. Support this website
6.1. Thank you
6.2. Questions and Discussion
7. Links and Literature
7.1. Apache Tomcat

1. Apache Tomcat

Apache Tomcat is a webcontainer which allows to run servlet and JavaServer Pages based web applications. Most of the modern Java web frameworks are based on servlets and JavaServer Pages and can run on Apache Tomcat, e.g. JavaServer Faces, Struts, Spring.

Apache Tomcat also provides by default a HTTP connector on port 8080, e.g. Tomcat can also be used as HTTP server even though the performance of Tomcat is not as good as the performance of the Apache HTTP server.

2. Installation

2.1. Ubuntu Linux

For Ubuntu you can install Tomcat via the following commands.

apt-get install tomcat7
apt-get install tomcat7-admin
apt-get install tomcat7-docs
apt-get install tomcat7-examples 

2.2. Windows

Download the Windows installer for Tomcat7 from the Apache Tomcat Homepage and run the installer.

3. Managing Apache Tomcat

3.1. Start Tomcat on Ubuntu (Linux)

In Ubuntu the Tomcat server is started automatically. To restart Tomcat use the following command.

# Restart
sudo /etc/init.d/tomcat7 restart

# Stop 
sudo /etc/init.d/tomcat7 stop 

3.2. Start Tomcat on Windows

To start Tomcat use tomcat7.exe in the bin directory.

3.3. Test Tomcat

The default port for Tomcat is 8080. After starting Tomcat on your local you can validate if Tomcat is running the URL: http://localhost:8080.

3.4. Admin console

Tomcat provides a webbased adminstration console which can be started via the following link.


The default user for the administration console of Tomcat is called admin with the admin password.

The available users can be found in the /conf/tomcat-users.xml directory of the Tomcat installation.

On Ubuntu the user for the administrator console is not created automatically, you have to add the user entry manually to the /etc/tomcat7/tomcat-users.xml . The following listing gives an example for a user. To get more information try to login and see the resulting error message.

<role rolename="manager-gui" />
<user username="tomcat" password="s3cret" roles="manager-gui" /> 

3.5. Deployment

The standard deployment format for webapplications is a .war file. If you have create a war application just put this application into the webapps folder. The next time tomcat starts it will unpack the war and make the application available.

Web applications may require external libraries. Typically web application contain there own libraries but if you want to make certain libraries available for all applications you can put them into the folder "lib" and a subfolder below "lib". These libraries are then available for all web applications.

4. Developing Java web applications

After going through the setup you probably want to learn how to develop servlets and JSP on installation directory. Please see Servlets and JSP development - Tutorial

5. Tomcat as HTTP Server

contains also a HTTP connector which can be used to serve static HTML pages. The standard directory which will be served is below the Tomcat webapps/ROOT below the installation directory. Place static content into this directory.

To allow directory browsing via Apache Tomcat change the listings parameter in the file conf/web.xml from false to true.


6. Support this website

This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.

Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.

6.1. Thank you

Please consider a contribution if this article helped you.

Flattr this

6.2. Questions and Discussion

If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

7. Links and Literature