Getting started with tomcat
Remarks#
This section provides an overview of what tomcat is, and why a developer might want to use it.
It should also mention any large subjects within tomcat, and link out to the related topics. Since the Documentation for tomcat is new, you may need to create initial versions of those related topics.
Versions#
Version | Java | Servlet | JSP | EL | WebSocket | JASPIC | Released |
---|---|---|---|---|---|---|---|
6.0.x | 5+ | 2.5 | 2.1 | 2.1 | n/a | n/a | 2006-12-01 |
7.0.x | 6+ | 3.0 | 2.2 | 2.2 | 1.1 | n/a | 2010-06-02 |
8.0.x | 7+ | 3.1 | 2.3 | 3.0 | 1.1 | n/a | 2013-08-05 |
8.5.x | 7+ | 3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 2016-06-13 |
9.0.x | 8+ | 4.0 | 2.4 | 3.1 | 1.2 | 1.1 | 2016-06-13 |
Installation or Setup
Detailed instructions on getting tomcat set up or installed.
Installing Tomcat as a service on Ubuntu
This example demonstrates how to install Tomcat as a service on Ubuntu using the *.tar.gz releases of both Tomcat as well as Java.
1. Install the Java Runtime Environment (JRE)
- Download the desired jre .tar.gz release
- Extract to
/opt/
This will create a directory/opt/jre1.Xxxx/
- Create a symbolic link to the java home directory:
cd /opt; sudo ln -s jre1.Xxxxx java
- add the JRE to the JAVA_HOME environment variable:
sudo vim /etc/environment
JAVA_HOME="/opt/java"
2. Install Tomcat:
- Download tomcat in a .tar.gz (or similiar) release.
- Create a tomcat system user:
sudo useradd -r tomcat
- Extract to
/opt/
This will create a directory/opt/apache-tomcat-XXXX
assign this directory to the tomcat system user and group:
sudo chown -R tomcat ./*
sudo chgrp -R tomcat ./*
- Create the
CATALINA_HOME
environment variable:
sudo vim /etc/environment
CATALINA_HOME="/opt/tomcat"
- Add admin user in
tomcat-users.xml
sudo vim /opt/tomcat/conf/tomcat-users.xml
and add something like<user username="admin" password="adminpw" roles="manager-gui">
between the<tomcat-users>
...</tomcat-users>
tags
3. Making Tomcat boot at startup
Add a script in /etc/init.d called tomcat and make it executable. The content of the script can look something like:
RETVAL=$?
CATALINA_HOME="/opt/tomcat"
case "$1" in
start)
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
sudo -u tomcat $CATALINA_HOME/bin/startup.sh
fi
;;
stop)
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
sudo -u tomcat $CATALINA_HOME/bin/shutdown.sh
fi
;;
*)
echo $"Usage: $0 {start|stop}"
exit 1
;;
esac
exit $RETVAL
To make it start on boot, run: sudo update-rc.d tomcat defaults
You can also add a bash line to /etc/rc.local for example service tomcat start
Changing classpath or other Tomcat related environment variables:
Edit the file $CATALINA_HOME/bin/setenv.sh
and add the properties in here, for example: CLASSPATH=/additional/class/directories