Running Apache Tomcat
These instructions assume that you have a functioning installation of the JDK (I'm using 1.6.0_21), and that the java and javac commands are in your path. I've tested briefly on both Windows and Red Hat Enterprise Linux, and the instructions work for me. This is a wiki, so if you have better instructions, feel free to edit.
- Go to http://tomcat.apache.org/ and find the download page for the latest version. As of this writing, that's version 7, available from http://tomcat.apache.org/download-70.cgi
- Download the Core zip file — that is, the first download available under the “Core” heading. Don't bother with any of the Windows-specific downloads; the Core works fine.
- Extract the contents of the zip file and move them somewhere appropriate, such as
c:\Program Files\Tomcat\or~/tomcat/. - Edit the file
conf/context.xmland change the line which reads:<Context>
so that it reads:
<Context reloadable="true">
- If you're going to be running JESS code, copy the
jess.jarfile from thelibfolder of your JESS installation into thelibfolder of your Tomcat installation. - Run the startup script. On Windows, this is
bin\startup.bat; on Linux and OS X, this isbin/startup.sh. - On Linux/OS X, the various shell scripts may not be executable;
chmod u+x *.shfrom the command line will fix that. - Launch a web browser and point it to http://localhost:8080/
- Make sure your browser displays the default Tomcat home page.
Adding your project to Tomcat
- Create a new folder for your project under the
webappsfolder of your Tomcat installation. - Inside that folder, create a new folder named
WEB-INF. - Inside the
WEB-INFfolder, create a folder namedclasses. - Copy the
.classfiles from your project into theclassesfolder, or copy the.javasource files and follow the instructions below to compile them. - Create a file named
web.xmlinside theWEB-INFfolder. Here's a sample:<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>HelloJess</servlet-name> <servlet-class>HelloJess</servlet-class> </servlet> <servlet-mapping> <servlet-name> HelloJess </servlet-name> <url-pattern> /index.html </url-pattern> </servlet-mapping> </web-app> - That
web.xmlfile will work for a program which implements a class namedHelloJess, as defined in the source like this:public class HelloJess extends HttpServlet {You will want to alter your
web.xmlfile accordingly. - Visit
http://localhost:8080/yourproect/, whereyourprojectis the name of the folder you created underwebapps. If everything worked, the output of your program will be here.
Compiling your code
You'll need to make sure that the servlet API and JESS classes are in your classpath when compiling. This command works for me, when my shell is in the classes folder under WEB-INF in the project folder under webapps:
javac -classpath ..\..\..\..\lib\jess.jar;..\..\..\..\lib\servlet-api.jar *.java
That's for Windows. For everything else, it would be:
javac -classpath ../../../../lib/jess.jar;../../../../lib/servlet-api.jar *.java
If you get the example code from the textbook web site (accessible from the CSS 482 web site, keep the .class files in the project directory, and are working on Linux or OS X, you can use the following modified Makefile to ease recompilation and reinstallation of your code:
.SUFFIXES: .java .class JAVA_HOME=/usr/java/latest CATALINA_HOME=$(HOME)/Documents/Classes/CSS482/apache-tomcat-7.0.4 APPNAME=HelloJess JESS=$(CATALINA_HOME)/lib/jess.jar JAVAC=/usr/bin/javac build: HelloJess.class Hello.class .java.class: $(JAVAC) -classpath .:$(JAVA_HOME)/jre/lib/rt.jar:$(CATALINA_HOME)/lib/servlet-api.jar:$(JESS) $< install: build cp *.class $(CATALINA_HOME)/webapps/$(APPNAME)/WEB-INF/classes clean: rm -f *~ *.class
You will need to change CATALINA_HOME to be your tomcat installation directory ($(HOME) refers to your home directory). After you edit a .java file, you can recompile and reinstall the new .class file using:
make install