Java Reference
In-Depth Information
The /WEB-INF/classes/ directory contains any Java classes required by the web
application. This includes servlet classes, JavaBeans, and custom tag implementa-
tions. Note that the classes must be in directories that correspond to their package
names. Thus, in the example, the actual class files are in a subdirectory: /WEB-INF/
classes/com/davidflanagan/examples/servlet/ .
The /WEB-INF/lib/ directory contains any JAR files required by the web applica-
tion. It might contain a tag library implementation packaged in JAR format, for
example. The /WEB-INF/tlds/ directory contains tag library descriptors, like the
/WEB-INF/tlds/decor_0_1.tld TLD file that describes the Decor custom tag library
used by the JSP pages.
Creating a WAR file for a web application is largely a matter of getting all the files
in the right place and packaging them up. Example 18-12 shows a Unix shell script
that automates this task. Windows users should have no trouble transforming this
script to a DOS batch file.
Example 18−12: makewar.sh: A Script for Packaging a Web Application
#!/bin/sh
# Delete all Java class files, and recompile everything
echo "Recompiling Java classes..."
rm *.class
javac *.java
# Create a temporary directory structure for the web application
echo "Creating WAR file..."
mkdir temp
mkdir temp/WEB-INF
mkdir temp/WEB-INF/tlds
mkdir temp/WEB-INF/classes
mkdir temp/WEB-INF/classes/com
mkdir temp/WEB-INF/classes/com/davidflanagan
mkdir temp/WEB-INF/classes/com/davidflanagan/examples
mkdir temp/WEB-INF/classes/com/davidflanagan/examples/servlet
# Now copy our files into those directories
cp *.jsp temp # JSP files go at the top level
cp WEB-INF/web.xml temp/WEB-INF # Configuration files in WEB-INF/
cp WEB-INF/tlds/decor_0_1.tld temp/WEB-INF/tlds
# Java class files go under WEB-INF/classes
cp *.class temp/WEB-INF/classes/com/davidflanagan/examples/servlet
# At this point, the temporary directory contains all our files, so
# we can jar them up into a WAR file with the name javaexamples2.war
# This WAR file can now simply be dropped into the Tomcat webapps/ directory.
cd temp
jar cMf ../javaexamples2.war *
# Now delete the temporary directory hierarchy
cd ..
rm -rf temp
Search WWH ::




Custom Search