Compiling Servlets on Ocelot

In order to compile servlets on oceleot, you will need to edit the .cshrc file and set up the CLASSPATH variable. The most important jar file is the servlet-api.jar file that is located in the Tomcat directory.

Editing .cshrc

Add the following commands to the .cshrc file to add the servlet-api.jar file and the classes directories of your web applications to the CLASSPATH variable.

Add these statements after

# User additions go below here
#
#
and before any other CLASSPATH statements.
#
#Define the location of Java
#
setenv JAVA_HOME /depot/J2SE-1.6
#
#Define the location of Tomcat
#
setenv TOM_HOME /home/ocelot/aul-user-web/apache-tomcat-7.0.21
#
#Add directories and jars to the CLASSPATH
#Replace my_webapp with the name of your webapp
#
set web_app_name=${USER}
setenv CLASSPATH {$TOM_HOME}/lib/servlet-api.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/ROOT/WEB-INF/classes
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/classes

if ( -e {$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/commons-beanutils.jar ) then
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/commons-beanutils.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/commons-collections-2.1.1.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/commons-logging-1.0.4.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/log4j-1.2.11.jar
endif

if ( -e {$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/ejb3-persistence.jar ) then
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/ejb3-persistence.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/hibernate-annotations.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/hibernate3.jar
setenv CLASSPATH {$CLASSPATH}:{$HOME}/cgs4854/webapps/$web_app_name/WEB-INF/lib/hibernate-validator.jar
endif

After you make changes to the .cshrc file, run the command

source ~/.cshrc

If there are any errors displayed on the screen, then you have made a mistake in the .cshrc file.

Compiling on Ocelot

The command to compile a file named FirstServlet.java is

  javac  FirstServlet.java

The .class file will be created in the same directory as the .java file. Be sure that the permissions on the .class file are 604.