MCS-270 Installing and Running Tomcat

Installing and launching Tomcat

  1. Extract your version of tomcat: Switch to your home directory, since that is where you should install tomcat. (You could put it elsewhere, but it will be better if you put it there, since it will then be easier for me to describe how to do this, and also to check for installation errors.) From your home directory, issue the following command:
        tar xfz ~karl/public/270/apache-tomcat-5.5.15.tar.gz
    
    This should create the directory apache-tomcat-5.5.15/

  2. To save time typing, put a symlink from tomcat in your home directory to the installation directory, apache-tomcat-5.5.15. (This should be done before changing directory.)
        ln -s `pwd`/apache-tomcat-5.5.15 ~/tomcat
    

  3. Create the directory where jsp applications will be stored:
       mkdir ~/webapps
       mkdir ~/webapps/WEB-INF
       mkdir ~/webapps/WEB-INF/classes
       mkdir ~/webapps/WEB-INF/lib
    

  4. Create a symlink in ~/tomcat/webapps/ to your webapps directory. This symlink will be of the form webapps-username; for example, mine is webapps-karl:
        ln -s ~/webapps ~/tomcat/webapps/webapps-`whoami`
    

  5. Set environment variable for JAVA_HOME to /usr/java/default In a csh shell, use
        setenv JAVA_HOME /usr/java/default
    
    In the bash shell, use
        export JAVA_HOME=/usr/java/default
    
    You'll probably want to also set up JAVA_HOME or other environment variables automatically when you log in by adding the above line(s) in your .cshrc file and/or .bashrc file respectively, depending on whether you use csh and/or bash.

  6. Start up tomcat:
        ~/tomcat/bin/startup.sh
    
    NOTE: You should shutdown tomcat when you are done using
        ~/tomcat/bin/shutdown.sh
    
    This frees up the 8080 port for a classmate. Also, you can make starting up, shutting down, and restarting tomcat easier by putting the following aliases in .cshrc:
        alias sta ~/tomcat/bin/startup.sh
        alias shu ~/tomcat/bin/shutdown.sh
        alias restart ~/tomcat/bin/shutdown.sh \; ~/tomcat/bin/startup.sh
    
    Then, you will only need to type sta, shu, or restart to have the desired effect.

  7. Copy my jsp work directory: Go to the directory where you want to do your jsp programming and issue the following command:
        cp -r ~karl/public/270/jsp .
    
    This will create a directory called jsp which currently contains two sub-directories, one called called hello, which contains the Hello World application I described in class yesterday, and another called num (which is described later).

  8. Install the Hello World application: Move to the jsp/hello directory and type the following command:
        make
    
    This will use the GNUMakefile in that directory to install the file hello.jsp in the directory ~/webapps.

  9. Launch the Hello World application: You can view sample jsp page by entering something like this in the URL:
        http://localhost:8080/webapps-username/hello.jsp
    

  10. Check-off: Show me that you have successfully viewed this file.

Comments

You'll want to launch tomcat yourself rather than using the tomcat process running on mcs-jsp.gac.edu for several reasons:

Where to put files

Restarting tomcat

When you create a new web application, you may need to restart tomcat for it to see the new application. Do so by
    ~/tomcat/bin/shutdown.sh ; ~/tomcat/bin/startup.sh
It'll take about 30 seconds to a minute to restart. If you did the aliases I described above, you will only need to type shu.

Ending tomcat

Please end your tomcat process before you leave in order to make the machine available for the next user. The correct way is to type
    ~/tomcat/bin/shutdown.sh
or you can choose the brutal but expedient,
    killall java
This will kill all java processes you have launched, including tomcat.

Installing class files

During development, it's convenient to keep all files in one directory. But, as mentioned before, for deployment, class files need to be in a separate directory.