geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Łukasz Budnik" <>
Subject [Solution] Ant and pre-compiled JSPs
Date Sat, 05 Apr 2008 13:24:37 GMT
Hi All,

If you use Ant to build your project you can use described below
solution to pre-compile JSPs.

It's extremely useful when you use complex JSP pages, for example
pages with MyFaces + Tomahawk + Tomahawk Sandbox load much faster!

First of all, you cannot use standard JspC task as described here:

You need to set
org.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS to true
which is simply impossible at the taskdef level.

In order to set this property and pass it to some other Java class you
need to use <java> task with nested <sysproperty>.

First of all the classpath:

<path id="jspc-classpath">
         <!-- taglib jsp core -->
location="${GERONIMO_HOME}\repository\jstl\jstl\1.2\jstl-1.2.jar" />
         <!-- taglib jsf core and html -->
         <!-- taglib tomahawk -->
         <!-- taglib tomahawk sandbox -->
         <!-- Geronimo's jasper -->
         <!-- required by Jasper -->
         <!-- if your web app uses some other libs, add it here -->
         <path refid="web-classpath" />
         <!-- JspC is also implemented as Ant Task - it needs Ant lib
when run as a Java class -->
         <pathelement location="${ant.home}\lib\ant.jar "/>

Now, use this target to compile JSP to servlets:

<target name="jspc">
		<!-- must use fork! otherwise there will be ClasCastException -
AntClassLoader cannot be casted to URLClassLoader! -->
		<java classname="org.apache.jasper.JspC" fork="true">
		  <classpath refid="jspc-classpath"/>
                  <!-- the key feature ;) -->
		  <arg value="-p"/>
		  <arg value="org.xh.nuntius.web.jsps"/>
		  <arg value="-webapp"/>
		  <arg value="${web-build}/classes"/>
		  <arg value="-webinc"/>
		  <arg value="${web-build}/classes/WEB-INF/generated_web.xml"/>
		  <arg value="-d"/>
		  <arg value="${web-build}/classes/WEB-INF/src"/>
		  <arg value="-source"/>
		  <arg value="1.5"/>
		  <arg value="-target"/>
		  <arg value="1.5"/>
		  <arg value="-s"/>

Now compile generated servlets to byte codes:

<target name="jspc-compile" depends="jspc">
		<javac srcdir="${web-build}/classes/WEB-INF/src"
classpathref="jspc-classpath" encoding="UTF-8" />

Note that before packaging your application the generated_web.xml must
be merged with your original web.xml.

And my suggestion:

If Geronimo team is using very own, enhanced Jasper version why not
assume that USE_INSTANCE_MANAGER_FOR_TAGS is always set to true?

It would be much easier for us all ;)

best regards
View raw message