8. Jakarta Tomcat

8.1. What is Tomcat

 

Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. The Java Servlet and JavaServer Pages specifications are developed by Sun under the Java Community Process.

From the authors point of view:

 
--jakarta.apache.org 

Tomcat is the successor of jserv which is no longer developed. Tomcat supports the latest jsp and servlet-APIs defined by sun. Unfortunately Tomcat is very difficult to build from source, because it is using its own building-system called "ant". There is also a very long list of prerequisites if you want to build from source. See http://jakarta.apache.org/tomcat/tomcat-4.0-doc/BUILDING.txt for more details - Good luck, and give some feedback to the author.

In the meantime the HOWTO is providing some basic support for Tomcat installed from binaries.

The Author is searching for some volunteers who tries to build Tomcat from source and tells what steps are required

8.2. Prerequisites

8.2.2. Download the binaries

Go to http://java.sun.com/j2se/1.3/ [1],choose your platform and follow the steps on the site.

8.3. Download the binaries

Origin-Site: http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/src/jakarta-tomcat-4.1.18-src.tar.gz

8.3.1. Installing the binaries

cd /usr/local

tar -xvzf jakarta-tomcat-4.1.8.tar.gz

cd jakarta-tomcat-4.1.8

cd bin

rm *.bat

echo export JAVA_HOME=/usr/lib/java/ >> /etc/profile
. /etc/profile

To enable the Tomcat manager, you need to modify /usr/local/jakarta-tomcat-4.1.8/conf/tomcat-users.xml add a user »admin« or with the role »manager«. The result should look like this:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="admin" password="secret" roles="manager"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="role1" password="tomcat" roles="role1"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
</tomcat-users>

Now you should be able to startup tomcat:
/usr/local/apache/jakarta-tomcat-4.1.8/bin/startup.sh

You should now be able to connect to: http://localhost:8080/index.jsp

8.4. mod_jk

8.4.2. Building and installing

tar -xvzf jakarta-tomcat-connectors-4.1.18-src.tar.gz

cd jakarta-tomcat-connectors-4.1.18-src/jk/native

./buildconf
./configure --with-apxs=/usr/local/apache/bin/apxs

make
make install

8.4.3. Customizing

Now follows the annoying part, the customizing of the config files. First edit /usr/local/jakarta-tomcat-connectors-4.1.18-src/jk/conf/workers.properties, and copy the file to /usr/local/apache/conf

I made a sample workers.properties that works with the example JSPs and servlets that comes with the Tomcat distribution. It is based on the sample workers.properties from Tomcat

Next, you need to configure your apache config file httpd.conf. The following example matches the examples provided by Tomcat.

LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c

JkWorkersFile /usr/local/apache/conf/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /examples/servlet/* worker1
JkMount /examples/*.jsp worker1 

After restarting Apache, you should now be able to connect to your JSP's via Apache. I.e: http://localhost/examples/jsp/num/numguess.jsp

For the further steps like installing your servlets and jsp-files, you are responsible by yourself...

TipEnvironment Variables
 

If Tomcat fails to start and/or your servlets could not be started the most common error made is having not all needed classes in the CLASSPATH variable.

Notes

[1]

There is also version 1.4.1 of Java available, but Tomcat seems not to run with that version of Java.