Tomcat (MCS-270, Spring 2004)
Each of your home directory's quotas has been increased to accomodate
a copy of tomcat.
Installing and launching Tomcat
- Extract the customized version of tomcat. Switch to the
directory in which you wish tomcat to be saved. I'll assume that's in
your home directory, but you could put it anywhere.
tar xfz ~wolfe/public/270/tomcat.tgz
This should create the directory
- To save time typing, put a symlink from tomcat in your home
directory to the installation directory, jakarta-tomcat-4.1.29. (This
should be done before changing directory.)
ln -s `pwd`/jakarta-tomcat-4.1.29 ~/tomcat
Create a sym link in
to your webapps directory. On mcs-jsp, I named the symlinks
webapps-username, so mine is
ln -s ~/webapps ~/tomcat/webapps/webapps-username
- Create your directory where
jsp applications will
Set environment variable for
csh shell, use
setenv JAVA_HOME /usr/java/j2sdk1.4.1_03/
bash shell, use
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
file respectively, depending on whether you use
- Start up tomcat:
NOTE: You should shutdown tomcat when you are done using
This frees up the 8080 port for a classmate.
Create a sample jsp page in your webapps directory such as hello.jsp.
View sample jsp page by entering something like this in the URL:
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
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.
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
or you can choose the brutal but expedient,
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.
- I've placed
numguess.jsp (distributed with tomcat) in a single
directory along with a Makefile which knows how to compile them. To
install, copy the directory to anywhere in your home directory:
cp -r ~wolfe/public/270/jspapps/num/ .
You should see 3 files; please read through them. Observe that the
GNUmakefile contains information (which you can edit)
about where the webapp files will be deployed.
- Install the webapp by editing the line of
GNUmakefile to your liking and then type
numguess.jsp in your browser just as you did
hello.jsp. (You may need to restart tomcat if tomcat
doesn't find it.)
- Now edit
NumberGuessBean.java to try some experiments. For
example, you could, for instance, make the game easy hard-coding your
favorite number as the answer. You could also put change the Bean so
that it outputs the guess by placing a line like
System.out.println("User guessed: " + guess)
in an appropriate place in
running the app, you can inspect the
catalina.out file to
trace the guesses.
- Try playing with other sample apps in
~/tomcat/webapps/examples/. You should make copies of
into source directories, like my
num directory, copy the
GNUmakefile and play.
- One last note: In order to install any code which
mysql, you'll need to
install the appropriate class files. You may wish to take care of
cp -r ~wolfe/public/270/java/com/ ~/tomcat/shared/classes/
These are class files which are shared among apps.