On Apr 5, 2008, at 9:24 AM, Ɓukasz Budnik wrote:
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:
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/jasper/JspC.html

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 -->
        <pathelement
location="${GERONIMO_HOME}\repository\jstl\jstl\1.2\jstl-1.2.jar" />
        <!-- taglib jsf core and html -->
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\myfaces\core\myfaces-impl\1.2.2\myfaces-impl-1.2.2.jar"/>
        <!-- taglib tomahawk -->
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\myfaces\tomahawk\tomahawk\1.1.7-SNAPSHOT\tomahawk-1.1.7-SNAPSHOT.jar"
/>
        <!-- taglib tomahawk sandbox -->
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\myfaces\tomahawk\tomahawk-sandbox\1.1.7-SNAPSHOT\tomahawk-sandbox-1.1.7-SNAPSHOT.jar"
/>
        <!-- Geronimo's jasper -->
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\tomcat\jasper\6.0.14-G614585\jasper-6.0.14-G614585.jar"
/>
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\tomcat\jasper-el\6.0.14\jasper-el-6.0.14.jar"
/>
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\geronimo\specs\geronimo-jsp_2.1_spec\1.0.1\geronimo-jsp_2.1_spec-1.0.1.jar"
/>
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\geronimo\specs\geronimo-el_1.0_spec\1.0.1\geronimo-el_1.0_spec-1.0.1.jar"
/>
        <!-- required by Jasper -->
        <pathelement
location="${GERONIMO_HOME}\repository\org\apache\tomcat\juli\6.0.14\juli-6.0.14.jar"
/>
        <!-- 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 "/>
</path>

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 ;) -->
 <sysproperty
key="org.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS"
value="true"/>
 <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"/>
</java>
</target>

Now compile generated servlets to byte codes:

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

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 ;)

Thanks Lukasz! Agreed we should make this easier...

--kevan