HOWTOlabs Tomcat
Java Servlet enabled web server

Tomcat is a servlet container enabled HTTP server written in Java that adheres to the Java Servlet and JavaServer Pages standard. As of this writting Tomcat 4.1 is the latest stable release. Typically Tomcat runs stand alone on port 8080 while listening on several other nearby ports for admin and control purposes.

As of Tomcat version 4, a 'lite edition' (LE) version of Tomcat has become available that leverages recent enhancements made in Java 1.4.1 and thereafter. Before Tomcat LE, it was traditional for Tomcat to include all sorts of extra bits to extend Java' capabilities.
 

 
Contents
Related
Elsewhere
Installation

Essentially, only Java needs to be present for Tomcat to run. It is possible that only J2RE (runtime edition) is necessary, however J2SE (Std Edition/SDK) is probably the more prudent Java version to have in place before launching Tomcat. Note: J2SE often downloads as a *.rpm.bin file which needs to be executed to extract the *.rpm file.

Linux
SETUP
# download j2sdk-1_4_1_02-fcs-linux-i586.rpm
  ... (also see OPTIONAL SETUP)
# rpm -ivh j2sdk-1_4_1_02-fcs-linux-i586.rpm
# ls /usr/java
j2sdk1.4.1_02
# download jakarta-tomcat-4.1.24-LE-jdk14.zip
  ...
# unzip jakarta-tomcat-4.1.24-LE-jdk14.zip
# mv jakarta-tomcat-4.1.24-LE-jdk14 /usr/local
# ln -s jakarta-tomcat-4.1.24-LE-jdk14 tomcat

OPTIONAL SETUP
# download j2sdk-1_4_1_02-linux-i586-rpm.bin
  ...
# chmod +x j2sdk-1_4_1_02-linux-i586-rpm.bin
./j2sdk-1_4_1_02-linux-i586-rpm.bin
  ... EULA, extract the rpm file ...
# rpm -ivh j2sdk-1_4_1_02-fcs-linux-i586.rpm
  ...
# vi /usr/local/tomcat/conf/server.xml
  port 8080 and other configuration settings can be changed

LAUNCH
# cd /tomcat/bin
# export JAVA_HOME="/usr/java/j2sdk1.4.1_02"
# sh tomcat/catalina start
Using CATALINA_BASE:   /tomcat
Using CATALINA_HOME:   /tomcat
Using CATALINA_TMPDIR: /tomcat/temp
Using JAVA_HOME:       /usr/java/j2sdk1.4.1_02
  Tomcat is now running in the background
#

OPTIONAL TEST
Point browser at http://[Tomcat system IP address]:8080/

SHUTDOWN
# sh tomcat/catalina stop
Using CATALINA_BASE:   /tomcat
Using CATALINA_HOME:   /tomcat
Using CATALINA_TMPDIR: /tomcat/temp
Using JAVA_HOME:       /usr/java/j2sdk1.4.1_02
  Tomcat is no longer running
#

Additional

Tomcat can be used in place of Apache to serve HTTP with server side Java. For general web serving, Apache performance will exceed what can be provided by Tomcat. In some situations, in may make sense to configure Tomcat to be invoked by Apache when Server Side Java is required. More on that soon.

Manually starting and stoping Tomcat may be problematic for certain production settings. There are RPM's for Linux that install Tomcat as a service. As a service the venerable service tomcat start mode of operation is enabled, which can further be automated with chkconfig and other tools used commonly with sendmail, httpd, named, and other UNIX/Linux stalwart services. More on that soon.

tomcatd
#!/bin/bash
#
# Startup script for Jakarta Tomcat
#
# chkconfig: 345 84 16
# description: Jakarta Tomcat Java Servlet/JSP Container


TOMCAT_HOME=/usr/local/tomcat
TOMCAT_START=/usr/local/tomcat/bin/startup.sh
TOMCAT_STOP=/usr/local/tomcat/bin/shutdown.sh

#Necessary environment variables
export CATALINA_HOME=/usr/local/tomcat
export JAVA_HOME=/usr/java/j2sdk1.4.1_02
export LD_KERNEL_ASSUME="2.2.5"

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

#Check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
    echo "Tomcat not available..."
    exit
fi

start() {
    echo -n "Starting Tomcat: "
    daemon $TOMCAT_START
    echo
    touch /var/lock/subsys/tomcatd
# We may need to sleep here so it will be up for apache
#    sleep 5
#Instead should check to see if apache is up by looking for http.pid
}

stop() {
    echo -n $"Shutting down Tomcat: "
    daemon $TOMCAT_STOP
    rm -f /var/lock/subsys/tomcatd.pid
    echo
}

status() {
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" \
    | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
    read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
    echo -n "tomcatd ( pid "
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" \
    | awk '{printf $1 " "}'
    echo -n ") is running..."
else
    echo -n "Tomcat is stopped"
fi
}

case "$1" in
    start)
        start
        ;;
     stop)
        stop
        ;;
     restart)
        stop
        sleep 3
        start
        ;;
     status)
        status
        ;;
     *)
        echo "Usage: tomcatd {start|stop|restart|status}"
     exit 1
esac
CHKCONFIG
# chkconfig --del tomcatd
# chkconfig --add tomcatd
# chkconfig --level 345 tomcatd on
# chkconfig --list tomcatd
# chmod +x /usr/local/tomcat/bin/*.sh
# service httpd
  ...

HTTPS
Secure http on port 8443
[root@sting conf]# rcsdiff -c server.xml
===================================================================
RCS file: server.xml,v
retrieving revision 1.1
diff -c -r1.1 server.xml
*** server.xml  2004/09/19 22:40:26     1.1
--- server.xml  2004/09/19 22:40:48
***************
*** 106,118 ****
        -->

      <!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
-     <!--
      <Connector port="8443"
                 maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                 enableLookups="false" disableUploadTimeout="true"
                 acceptCount="100" debug="0" scheme="https" secure="true"
                 clientAuth="false" sslProtocol="TLS" />
-     -->

      <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
      <Connector port="8009"
--- 106,116 ----
AXIS
Once Tomcat is installed and working, notice that it has a webapps
directory.

SETUP
After downloading the latest AXIS image, expand it and notice that it too
has a webapps directory.  Within this directory is an axis directory.
  $ cp -R axis/webapps/axis tomcat/webapps

OPTIONAL SETUP
  $ cp -R tomcat/webapps/axis/WEB-INF/lib/jaxrpc.jar tomcat/common/lib
  $ cp -R tomcat/webapps/axis/WEB-INF/lib/saaj.jar   tomcat/common/lib

OPTIONAL SETUP
  $ download jaf-1_0_2.zip
  $ cp activation.jar /usr/local/tomcat/common/lib

OPTIONAL TEST
http://[Tomcat system IP address]:8080/axis/
http://[Tomcat system IP address]:8080/axis/happyaxis.jsp <- Validation