Apache Tomcat. This article describes the installation and usage of Apache Tomcat for Java web development.
Apache Tomcat is a webcontainer which allows to run Java web applications. Most of the modern Java web frameworks are based on servlets, e.g. JavaServer Faces, Struts, Spring.
Apache Tomcat also provides by default a HTTP connector on port 8080, i.e., Tomcat can also be used as HTTP server. But the performance of Tomcat is not as good as the performance of a designated web server, like the Apache HTTP server.
For Ubuntu you can install Tomcat via the following commands.
sudo apt install tomcat8 tomcat8-admin tomcat8-docs tomcat8-examples
Download the Windows installer for Tomcat8 from the Apache Tomcat Homepage and run the installer.
To setup the default port to which Tomcat is listening, us
In Ubuntu the Tomcat server is started automatically. To restart Tomcat you can use the following command.
# Restart sudo /etc/init.d/tomcat8 restart # Stop sudo /etc/init.d/tomcat8 stop
To start Tomcat use
tomcat8.exe in the bin directory.
The default port for Tomcat is 8080. After starting Tomcat on your local machine, you can validate if Tomcat is running the URL:
This should show a web page similar to the following.
Tomcat provides a webbased adminstration console which can be started via the following link:
The available users can be found in the
This file is located of the Tomcat configuration directory, i.e., the
/etc/tomcat/tomcat-users.xml file under Ubuntu.
On Ubuntu the user for the administrator console is not created automatically.
You have to add the user entry manually to the
The following listing gives an example for a user.
To get more information try to login and see the resulting error message.
you entered a user and a password, restart the Tomcat server to
ensure your new users is activated.
<role rolename="manager-gui" /> <user username="tomcat" password="s3cret" roles="manager-gui" />
The default user for the Tomcat administration console under Windows is admin with the admin password.
The standard deployment format for webapplications is a
you create a war application just put this application
folder. The next time tomcat starts it will unpack
and make the
Web applications may require external libraries. Typically, web application contain their 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.
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
contains also a HTTP connector which can be used
to serve static HTML
pages. The standard directory which will be
served is below the
below the installation directory. Place static content
into this directory.
To allow directory browsing via Apache Tomcat change the
in the file
from false to true.
<servlet> <servlet-name>default</servlet-name> <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
Copyright © 2012-2018 vogella GmbH. Free use of the software examples is granted under the terms of the Eclipse Public License 2.0. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.