Web Application Compilation

Using Ant is the preferred way to compile web applications using JSPC. Note that when pre-compiling JSPs, SMAP information will only be included in the final classes if suppressSmap is false and compile is true. Use the script given below (a similar script is included in the “deployer” download) to precompile a webapp:

 

<project name=”Webapp Precompilation” default=”all” basedir=”.”>

<import file=”${tomcat.home}/bin/catalina-tasks.xml”/>

 

<target name=”jspc”>

 

<jasper

validateXml=”false”

uriroot=”${webapp.path}”

webXmlFragment=”${webapp.path}/WEB-INF/generated_web.xml”

outputDir=”${webapp.path}/WEB-INF/src” />

 

</target>

<target name=”compile”>

<mkdir dir=”${webapp.path}/WEB-INF/classes”/>

<mkdir dir=”${webapp.path}/WEB-INF/lib”/>

 

<javac destdir=”${webapp.path}/WEB-INF/classes”

optimize=”off”

debug=”on” failonerror=”false”

srcdir=”${webapp.path}/WEB-INF/src”

excludes=”**/*.smap”>

<classpath>

<pathelement location=”${webapp.path}/WEB-INF/classes”/>

<fileset dir=”${webapp.path}/WEB-INF/lib”>

<include name=”*.jar”/>

</fileset>

<pathelement location=”${tomcat.home}/lib”/>

<fileset dir=”${tomcat.home}/lib”>

<include name=”*.jar”/>

</fileset>

<fileset dir=”${tomcat.home}/bin”>

<include name=”*.jar”/>

</fileset>

</classpath>

<include name=”**” />

<exclude name=”tags/**” />

</javac>

 

</target>

 

<target name=”all” depends=”jspc,compile”>

</target>

 

<target name=”cleanup”>

<delete>

<fileset dir=”${webapp.path}/WEB-INF/src”/>

<fileset dir=”${webapp.path}/WEB-INF/classes/org/apache/jsp”/>

</delete>

</target>

 

</project>

The following command line can be used to run the script (replacing the tokens with the Tomcat base path and the path to the webapp which should be precompiled):

$ANT_HOME/bin/ant -Dtomcat.home=<$TOMCAT_HOME> -Dwebapp.path=<$WEBAPP_PATH>

Then, the declarations and mappings for the servlets which were generated during the precompilation must be added to the web application deployment descriptor. Insert the ${webapp.path}/WEB-INF/generated_web.xml at the right place inside the ${webapp.path}/WEB-INF/web.xml file. Restart the web application (using the manager) and test it to verify it is running fine with precompiled servlets. An appropriate token placed in the web application deployment descriptor may also be used to automatically insert the generated servlet declarations and mappings using Ant filtering capabilities. This is actually how all the webapps distributed with Tomcat are automatically compiled as part of the build process.

At the jasper task you can use the option addWebXmlMappings for automatic merge the ${webapp.path}/WEB-INF/generated_web.xml with the current web application deployment descriptor at ${webapp.path}/WEB-INF/web.xml. When you want to use Java 6 features inside your jsp’s, add the following javac compiler task attributes: source=”1.6″ target=”1.6″. For live applications you can also compile with optimize=”on” and without debug info debug=”off”.

When you don’t want to stop the jsp generation at first jsp syntax error, use failOnError=”false”and withshowSuccess=”true” all successfull jsp to java generation are printed out. Sometimes it is very helpful, when you cleanup the generate java source files at ${webapp.path}/WEB-INF/src and the compile jsp servlet classes at${webapp.path}/WEB-INF/classes/org/apache/jsp.

Hints:

  • When you switch to another Tomcat release, then regenerate and recompile your jsp’s with the new Tomcat version.
  • Use java system property at server runtime to disable PageContext poolingorg.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false. and limit the buffering withorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true. Note that changing from the defaults may affect performance, but it will vary depending on the application.
Share this post
[social_warfare]
Production Configuration
Optimisation

Get industry recognized certification – Contact us

keyboard_arrow_up