Installing Jakarta Tomcat

The following instructions assume that you are using an account on cs-server.usc.edu.  To log into the csci571 machine, at the UNIX prompt run:

ssh yourloginname@cs-server.usc.edu


 Install Jakarta Tomcat

Download the Tomcat binary package jakarta-tomcat-4.1.27.tar from:

-OR- download the Tomcat binary package jakarta-tomcat-4.1.27.tar.gz from:

Place it in the ~/Tomcat directory (you may have to create this directory). Use the following command to unpack the .gz and/or the .tar package:

gunzip jakarta-tomcat-4.1.27.tar.gz

gtar xvf jakarta-tomcat-4.1.27.tar

The directory jakarta-tomcat-4.1.27 is created by the tar program under the ~/Tomcat/directory. You should delete jakarta-tomcat-4.1.27.tar which is no longer needed


Note:  You should use the GNU version of the tar program, gtar. The Solaris version of tar evidently has some bug in it that makes it not work with some tar files. Gtar should be available on your host machine. If it is not, the gtar-sparc version can be downloaded from http://www.mysql.com/downloads/os-solaris.html. Apparently, some versions of IE (I assume it's the browser) automatically unzip the file. When gunzip doesn't apparently work on gtar-sparc, use the mv command to remove the .gz extension and then do the chmod command and everything should work fine. Once you've downloaded the gtar-sparc program, gunzip it, and make it executable by using the commands:

$ gunzip gtar-sparc.gz

$ chmod +x gtar-sparc


 Set Up Environment for Java

Tomcat needs the Java Virtual Machine (JVM) to run. Also, for Tomcat 4.1 to work properly, you must be running version 1.3.1 or later of the JVM. In your root directory (/auto/home-scf-xx/YOUR-USERNAME/ or ~/), invoke a shell script that sets up new environment variables for the Java Virtual Machine version 1.4.0, by appending the following lines to the file .cshrc:

setenv JAVA_HOME /usr/j2se
setenv PATH /usr/j2se/bin:${PATH}

After updating the .cshrc file, either logout and login again or type the following command:

source .cshrc.

At this point you should check that the correct version of the JVM is in your path. At the prompt run:

java -version.

The result should be:

java version "1.4.2_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_13-b06)
Java HotSpot(TM) Client VM (build 1.4.2_13-b06, mixed mode)

If you are getting the output above, you are running version 1.4.0 of the JVM. As an added check, you should verify that the JAVA_HOME and PATH environment variables have been set as follows (note typing env at the prompt will list the values of your environment variables):

PATH=<other paths>:/usr/j2se/bin:...

JAVA_HOME=/usr/j2se


 Set Up Environment for Tomcat

In your root directory (/auto/home-scf-xx/YOUR-USERNAME/ or ~/), set new environment variables pointing to your tomcat directory, by appending the following lines to the file .cshrc:

setenv CATALINA_HOME ~/Tomcat/jakarta-tomcat-4.1.27

setenv JAVA_OPTS -Xmx64M

The last environment variable setting allows the JVM heap to grow to 64MB. You will get an OutOfMemoryException if you do not set this option. After updating the .cshrc file, either logout and login again or type the following command:

source .cshrc.


 Set Up Configuration for Jakarta Tomcat

You must now edit a configuration file in the Tomcat/jakarta-tomcat-4.1.27/conf directory. The name of the file is server.xml. You will have to change the assignment of three port numbers. The port numbers you will use are XXXXX+1, XXXXX+2 and XXXXX+3 where XXXXX are the last 5 digits of the random number that was assigned to you when you joined the class list. Load the file $CATALINA_HOME/conf/server.xml file into an editor and:

  1. Locate the first line that contains the phrase port="8005"
    Change the value of 8005 to XXXXX+2. The code that contains that line looks like this:
    <Server className="org.apache.catalina.core.StandardServer" debug="0" port="8005" shutdown="SHUTDOWN">
    
  2. Locate the first line that contains the phrase port="8080"
    Change the value of 8080 to XXXXX+1. The code that contains that line looks like this:
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" acceptCount="100" 
       bufferSize="2048" compression="off" connectionLinger="-1" connectionTimeout="20000"
       debug="0" disableUploadTimeout="true" enableLookups="true" maxKeepAliveRequests="100"
       maxProcessors="75" minProcessors="5" port="8080" protocolHandlerClassName=
       "org.apache.coyote.http11.Http11Protocol" proxyPort="0" redirectPort="8443" 
       scheme="http" secure="false" tcpNoDelay="true" useURIValidationHack="false">
    
  3. Locate the first line that contains the phrase port="8009"
    Change the value of 8009 to XXXXX+3. The code that contains that line looks like this:
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" acceptCount="10" 
       bufferSize="2048" compression="off" connectionLinger="-1" connectionTimeout="0" 
       debug="0" disableUploadTimeout="false" enableLookups="true" maxKeepAliveRequests="100" 
       maxProcessors="75" minProcessors="5" port="8009" protocolHandlerClassName=
       "org.apache.jk.server.JkCoyoteHandler" proxyPort="0" redirectPort="8443" 
       scheme="http" secure="false" tcpNoDelay="true" useURIValidationHack="false">
    

You should also enable the manager and administration applications. In order to do this, you should edit the file $CATALINA_HOME/conf/tomcat-users.xml. You will have to insert the two keywords: manager and admin, into the line that begins with the tag <user as follows:

<user username="tomcat" password="tomcat" roles="tomcat,manager,admin" />

You may also change the tomcat password at this time, if you wish to.


Test the Standalone Tomcat Web Server

cd $CATALINA_HOME/bin/, and type startup.sh Running this shell script file should produce an output similar to this:

cs-server.usc.edu(8): startup.sh
Using CATALINA_BASE: /auto/cs-00/user/jakarta-tomcat-4.1.27
Using CATALINA_HOME: /auto/cs-00/user/jakarta-tomcat-4.1.27
Using CATALINA_TMPDIR: /auto/cs-00/user/jakarta-tomcat-4.1.27/temp
Using JAVA_HOME: /usr/j2se

It will take a while to load the server the first time (as much as 1 minute). Check the log file, $CATALINA_HOME/logs/tomcat.log, for loading errors. To make sure that the Tomcat process is running, use the "ps" command as follows:

cs-server.usc.edu(9): ps -gx
PID TT S TIME COMMAND
23467 pts/65 S 0:00 -csh
24385 pts/65 S 0:22 /usr/j2se/bin/java -Xmx64M -Djava.endorsed.dir ...

Open a browser and go to http://cs-server.usc.edu:http-port#, using XXXXX+1 as your port. Try the JSP and Servlet Examples to make sure JSP and Servlets are working.


Test the Tomcat Application Development Environment
THIS SECTION IS NOT REQUIRED AND MAY BE SKIPPED

Step 1. Install Ant

To use the Tomcat Application Environment you must first install Ant. Instructions on how to install Ant can be found here.

Copy the file $CATALINA/server/lib/catalina-ant.jar from your Tomcat 4 installation into the "lib" directory of your Ant installation.

Step 2: Add manager, admin to tomcat roles in $CATALINA_HOME/conf/tomcat-users.xml:

<user name="tomcat" password="tomcat" roles="standard,admin,manager" />

Step 3: Edit build.xml in $CATALINA/webapps/tomcat-docs/appdev/sample , as follows:

<property name="catalina.home" value="/auto/cs-00/user/Tomcat/jakarta-tomcat-4.1.27"/> <!-- edit path (should point to same dir as $CATALINA_HOME) -->

<property name="manager.username"   value="tomcat"/> <!-- add line -->

<property name="manager.password"   value="tomcat"/> <!-- add line -->

<property name="manager.url"   value="http://localhost:8080/manager"/> <!-- edit port# -->

Step 4. Compile sample application in $CATALINA/webapps/tomcat-docs/appdev/sample:

ant all (compile source files)

ant dist  (generate javadoc and WAR file)

ant install (install application as /myapp) [needs tomcat to be running]

ant list (list installed/running applications)

The last command should produce an output similar to this:

    [list] OK - Listed applications for virtual host localhost
    [list] /manager:running:0:../server/webapps/manager
    [list] /examples:running:1:examples
    [list] /myapp:running:0:/auto/cs-00/user/jakarta-tomcat-4.1.27/webapps/tomcat-docs/appdev/sample/build
    [list] /tomcat-docs:running:0:/auto/cs-00/user/jakarta-tomcat-4.1.27/webapps/tomcat-docs
    [list] /webdav:running:0:/auto/cs-00/user/jakarta-tomcat-4.1.27/webapps/webdav
    [list] /:running:1:/auto/cs-00/ user /jakarta-tomcat-4.1.27/webapps/ROOT
    [list] /admin:running:1:../server/webapps/admin

(notice the fourth entry, myapp)

Step 5. Test the sample application

Open a browser and go to http://cs-server.usc.edu:http-port#/myapp . The Sample “Hello World” Application should appear. Test both the JSP and Servlets links.

Step 6. Remove the Application

ant remove

Step 7. Install WAR file

The WAR FILE is $CATALINA/webapps/tomcat-docs/appdev/sample/dist/myapp-0.1-dev.war. You can list and verify that all the appropriate files have been included in it, by running the “jar” program:

cs-server.usc.edu(10): jar tvf myapp-0.1-dev.war
   0 Fri Aug 29 23:54:16 GMT-08:00 2003 META-INF/
   0 Fri Aug 29 23:54:14 GMT-08:00 2003 META-INF/MANIFEST.MF
   0 Fri Aug 29 23:48:20 GMT-08:00 2003 images/
   0 Fri Aug 29 23:48:20 GMT-08:00 2003 WEB-INF
   0 Fri Aug 29 23:48:22 GMT-08:00 2003 WEB-INF/classes/
   0 Fri Aug 29 23:48:22 GMT-08:00 2003 WEB-INF/classes/mypackage/
   0 Fri Aug 29 23:48:20 GMT-08:00 2003 WEB-INF/lib/
1019 Fri Aug 29 23:48:20 GMT-08:00 2003 hello.jsp
1441 Fri Aug 29 23:48:20 GMT-08:00 2003 images/tomcat.gif
 636 Fri Aug 29 23:48:20 GMT-08:00 2003 index.html
2349 Fri Aug 29 23:48:22 GMT-08:00 2003 WEB-INF/classes/mypackage/Hello.class
 684 Fri Aug 29 23:48:20 GMT-08:00 2003 WEB-INF/web.xml

Install the WAR file from the Tomcat Manager, using “Upload a WAR file to install” and browse, selecting “myapp-0.1-dev.war”.

Step 8. Build your own application.

You should be able to copy the “sample” directory, its subdirectories and files and use them as a base for building your own JSP/Servlet based applications. Also read the document titled “Developing Applications With Tomcat” found on your server at:

$CATALINA_HOME/webapps/tomcat-docs/appdev/index.html