ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael 'Mickey' Sattler" <>
Subject pre-compiling java servlets under Tomcat using Ant
Date Tue, 29 May 2001 21:11:35 GMT
There's been a lot of chatter on the tomcat-user list on the subject 
of pre-compiling java servlets under Tomcat. (I include the most 
complete on the topic below for anyone interested.)

Before I dig in and convert these DOS-based non-Ant instructions into 
something I can use under UNIX I wanted to ask y'all whether anyone 
out there had already created an Ant task which pre-compiles java 
servlets as necessary?

(I'm mostly interested in pre-compiling so my clients don't get that 
"first visit slowdown" behavior. I can't guarantee that I'll be able 
to manually visit every web page to have Tomcat compile it.)

Thank you for reading this far. It's really appreciated.

  ** snip **

The following has been tested with Tomcat 3.2.1
Jspc in Tomcat 3.1 did not work.

The process is the following:

1.	Translate all jsp pages to java Servlet files and generate a web.xml
2.	Fix web.xml \ to /
3.	Compile all generated java files
4.	Deploy and run as a Servlet

Step 1:
This can be done with the jspc utility.  For example (on line dos command!):

\tomcat\bin\jspc -uriroot \tomcat\webapps\TxMA
    -d \tomcat\webapps\TxMA\WEB-INF\classes
    -webxml \tomcat\webapps\TxMA\WEB-INF\web.xml
    -webapp \tomcat\webapps\TxMA

-uriroot specifies the root of the web application
-d specifies the output directory.  The Servlet class files have to be
located under WEB-INF\classes.
-webxml specifies you need a full web.xml file.  This is a key step in the
process because that file will contain mappings for all URLs to their
Servlet equivalent (thus we don't have to rewrite all our href hyperlinks
when running in Servlet mode).
-webapp specifies we want to translate the complete application

Step 2:
Substitute all \ with /
This is because of a bug in the current implementation of jspc (on windows

Step 3:

The key of that step is to have the proper libraries in the classpath.

Here is a dos batch file that would do it:

SET JAVA_HOME=e:\jdk1.3.0_01
set TOMCAT_HOME=e:\tomcat321

set CP=%TOMCAT_HOME%\lib\ant.jar
set CP=%CP%;%TOMCAT_HOME%\lib\jasper.jar
set CP=%CP%;%TOMCAT_HOME%\lib\jaxp.jar
set CP=%CP%;%TOMCAT_HOME%\lib\parser.jar
set CP=%CP%;%TOMCAT_HOME%\lib\servlet.jar
set CP=%CP%;%TOMCAT_HOME%\lib\webserver.jar

set CP=%CP%;%JAVA_HOME%\lib\tools.jar

set CP=%CP%;%TOMCAT_HOME%\webapps\TxMA\WEB-INF\classes

echo Using CLASSPATH: %CP%

echo ON
javac %TOMCAT_HOME%\webapps\TxMA\WEB-INF\classes\*.java

  ** snip **
Michael "Mickey" Sattler, Geek Times   <>
San Francisco, California, USA    <>

I was born not knowing and have had only a little time to change that here
and there. -- Richard Feynman (1918 - 1988)

View raw message