SWE 432 Servlet Deployment Instructions
20-Oct-2014 -UP
Please tell me if you find any errors or omissions in the document. -JO
The software engineering group has collaborated with IT&E's computing support staff
to provide an application server for servlets and JSPs (apps-swe432)
for you to use as your "target deployment computer".
This server supports J2EE with the open-source platform Tomcat.
The server is called apps-swe432 and is part of the Hermes Cluster.
I will use the name apps-swe432 in the course and in this page.
This page presents step-by-step instructions to deploy your Servlets
and JSPs to the Tomcat application server on apps-swe432.
The server is behind the IT&E fire wall.
Therefore, you will need to use the Virtual Private Network (VPN) application
to access it from outside the off-campus.
Or, you can access it directly in a VSE Computer Lab.
If you are using the computer lab,
the steps are straightforward and you can skip to the "Deploy and Test" section.
To access the server and deploy your code from outside the firewall,
you need to follow these steps:
-
Review the information provided about the VPN tool from
http://labs.vse.gmu.edu/index.php/Services/VPN.
-
Follow the "Setup Instructions" to install the VPN tool on your computer.
(This will not take long.)
If your browser hesitates to go to the VPN download page because of
security certificate issues, it's okay. Simply tell your browser to
accept the certificate IT&E uses (CACERT).
-
Run the VPN tool as described in the instructions.
You will need your GMU email username and password.
Once connected,
your computer will be given an IP address that will connect it to the network
within the IT&E fire wall.
- Connect to the apps-swe432.vse.gmu.edu server using SSH or SFTP.
- Enter apps-swe432.vse.gmu.edu into the "Host Name" field,
your user name into the "User Name" field,
and 22 into the "Port Number field.
-
For a complete walkthrough of setting up OpenVPN (and SSH) on Windows XP go to
http://labs.vse.gmu.edu/index.php/FAQ/FAQ
-
Please Note:
If you disconnect the VPN tool,
or the connection times out, your SSH or SFTP session will be lost.
Therefore SAVE YOUR WORK OFTEN.
- Note that your password on apps-swe432 is the same as your GMU email password.
Now that you are connected to the server,
you can deploy and test your code.
The server can accept many different formats, including WAR and .class.
The rest of these instructions assume you are deploying a simple .class file.
To deploy your servlet, follow these steps:
- Write your servlet to belong to a package belonging to your GMU username.
For example, I would add the command:
package offutt;
to my servlet.
When compiling with javac, you will need to compile from "above" the directory:
javac
offutt/Hello.java.
-
Make a directory for your Java class package under
/data/apps-swe432/swe432/WEB-INF/classes.
- For example: mkdir /data/apps-swe432/swe432/WEB-INF/classes/username
- Note: Use your GMU username as a name for the package and the directory (to ensure uniqueness)
- Use the SSH Secure File Transfer Client (sftp)
to copy your .class files from your computer to the folder you just created on apps-swe432.
- Note: You can also use sftp to place the file into your home directory on apps-swe432,
then use the Unix move command (mv) to move the file
to the deployment directory through an ssh window on apps-swe432:
mv Hello.class /data/apps-swe432/swe432/WEB-INF/classes/username
- Do not put your .java source files into the public directory!
This would be an honor code violation.
- Test your servlet using the following URL:
-
NOTE: make sure that your files are readable.
- To make your files readable, run the Unix command on apps-swe432:
cd /data/apps-swe432/swe432/WEB-INF/classes/username
chmod 644 *
J2EE applications can also be deployed as "WAR" files.
A Java WAR file contains a compressed directory structure that mirrors the directory structrure in a servlet context.
That is, it contains a
WEB-INF/classes/,
web.xml/, etc.
WAR files (with the extension .war) are placed in the top level tomcat directory
(/data/apps-swe432/ on apps-swe432).
When tomcat sees the WAR file,
it unpacks the file into a directory, which becomes a new context.
So, if we deploy a WAR file called HelloWorld.war,
with a hello.jsp file contained at the root of the directory,
then the URL would be http://apps-swe432.vse.gmu.edu:8080/HelloWorld/hello.jsp.
WAR stands for
Web Application Archives.
WAR files can be created in three ways:
- With the packager tool distributed with the J2EE SDK.
- With the war task of the ant portable build tool, for example, ant.
- With the JAR tool distributed with the J2EE (and part of JDK).
If you arrange your application development directory in the structure required by the WAR format,
execute the following command in the top-level directory of the application:
jar cvf archiveName.war .
-
We have one servlet context for our class,
so all 432 students will put our servlets in the same directory.
Therefore we will
(1) create package subdirectories for our servlets based on our user names, or
(2) use the convention of prefacing our Java servlet classes with our user names.
So, my servlet would be "X"
and is accessed within my package directory with the "dot" notation,
"offutt.X",
or my servlet would be "offuttX".
-
To compile on apps-swe432, you will need to set your CLASSPATH variable.
CLASSPATH=$CLASSPATH:.:/usr/share/java/:/usr/share/java/servlet.jar ; export CLASSPATH
You can run this command from the command line each time you log in,
or you can put command in the file .bash_profile in your home directory.
-
Tomcat keeps its log files in the directory:
/usr/share/tomcat6/logs/.
The files "catalina.out" and
"apps_access_log.2009-MM-DD.txt"
accumulate log entries from Tomcat.
("MM" is a 2-digit indicator of the month and
"DD" is a 2-digit indicator of the day.)
You can look here to find error messages from your servlets.
NOTE, never ever do this:
try
{
... ...
} catch(Exception e) {
System.out.println (e.getMessage());
System.exit (0);
}
The servlet is running inside Tomcat, so this will cause Tomcat to exit.
All of your classmates will be very angry!
© Jeff Offutt, 2001-2012, all rights reserved.
This document is made available for use by GMU students of SWE 432.
Copying, distribution or other use of this document
without express permission of the author is forbidden.
You may create links to pages in this web site,
but may not copy all or part of the text without permission
of the author.