Jasper: Problem resolved?

Posted by Uncle Bob on 02/08/2007

After digging around in the Jasper source code, and fiddling hither and yon with various build.xml configurations, I finally (and quite by accident) hit on the solution to my trouble…

Grumble!

I don’t know why this works, but it does. If any of you out there are having trouble precompiling your jsps that use custom tags this might help.

 <target name="jsp" depends="dist">

   <delete dir="${basedir}/testjsp"/>

   <java classname="org.apache.jasper.JspC" fork="true">

     <arg line="-v -d ${basedir}/testjsp -p com.objectmentor.library.jsp -mapped -compile -webapp ${build.war.home}"/>

     <arg line="WEB-INF/pages/books/manage.jsp"/>

     <classpath>

       <fileset dir="${catalina.home}/common/lib">

         <include name="*.jar"/>

       </fileset>

       <fileset dir="${catalina.home}/server/lib">

         <include name="*.jar"/>

       </fileset>

       <fileset dir="${catalina.home}/bin">

         <include name="*.jar"/>

       </fileset>

       <fileset dir="${build.war.home}/WEB-INF/lib">

         <include name="*.jar"/>

       </fileset>

       <pathelement location="/Developer/Java/Ant/lib/ant.jar"/>

     </classpath>

   </java>

   <jar jarfile="${build.jar.home}/jsp.jar" basedir="${basedir}/testjsp"

        includes="**/jsp/**/*.class"

     />

 </target>

Notice the second <arg> tag. If you put the file name of the jsp you want to compile on the command line, it compiles the jsp correctly. If you leave it off, then even though all the documentation says that it will scan for all the jsps in the web app and compile them correctly, it will do the former, but not the latter. It will find all the jsps, but it wont compile them correctly. It will fail to statically initialize the _jspx_dependants variable in the generated code.

I am not at all sure why the compiler behaves this way. I looked at the Jasper code, but I didn’t feel like working my way through it to debug it. There is some funny business in the JspC.locateUriRoot function where it writes the file path of the file argument on top of the uribase command line argument. That might be the problem. But I’m not at all sure.

Anyway, there’s a new unit test for someone to write. (sigh).

Now I can write my unit test!

BTW I am using Tomcat 5.5.20

Comments

Leave a response