tomcat Getting started with tomcat

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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

VersionJavaServletJSPELWebSocketJASPICReleased
6.0.x5+2.52.12.1n/an/a2006-12-01
7.0.x6+3.02.22.21.1n/a2010-06-02
8.0.x7+3.12.33.01.1n/a2013-08-05
8.5.x7+3.12.33.01.11.12016-06-13
9.0.x8+4.02.43.11.21.12016-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)

  1. Download the desired jre .tar.gz release
  2. Extract to /opt/
    This will create a directory /opt/jre1.Xxxx/
  3. Create a symbolic link to the java home directory:
    cd /opt; sudo ln -s jre1.Xxxxx java
  4. add the JRE to the JAVA_HOME environment variable:
    sudo vim /etc/environment
    JAVA_HOME="/opt/java"

2. Install Tomcat:

  1. Download tomcat in a .tar.gz (or similiar) release.
  2. Create a tomcat system user:
    sudo useradd -r tomcat
  3. 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 ./*
  4. Create the CATALINA_HOME environment variable:
    sudo vim /etc/environment
    CATALINA_HOME="/opt/tomcat"
  5. 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



Got any tomcat Question?