<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Jasper: Problem resolved?</title>
    <link>http://blog.objectmentor.com/articles/2007/02/08/jasper-problem-resolved</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Jasper: Problem resolved?</title>
      <description>&lt;p&gt;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&amp;#8230;&lt;/p&gt;


	&lt;h2 style="text-align:center;"&gt;Grumble!&lt;/h2&gt;


I don&amp;#8217;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.  
&lt;pre&gt;&lt;code&gt;
  &amp;lt;target name="jsp" depends="dist"&amp;gt;
    &amp;lt;delete dir="${basedir}/testjsp"/&amp;gt;
    &amp;lt;java classname="org.apache.jasper.JspC" fork="true"&amp;gt;
      &amp;lt;arg line="-v -d ${basedir}/testjsp -p com.objectmentor.library.jsp -mapped -compile -webapp ${build.war.home}"/&amp;gt;
      &amp;lt;arg line="WEB-INF/pages/books/manage.jsp"/&amp;gt;
      &amp;lt;classpath&amp;gt;
        &amp;lt;fileset dir="${catalina.home}/common/lib"&amp;gt;
          &amp;lt;include name="*.jar"/&amp;gt;
        &amp;lt;/fileset&amp;gt;
        &amp;lt;fileset dir="${catalina.home}/server/lib"&amp;gt;
          &amp;lt;include name="*.jar"/&amp;gt;
        &amp;lt;/fileset&amp;gt;
        &amp;lt;fileset dir="${catalina.home}/bin"&amp;gt;
          &amp;lt;include name="*.jar"/&amp;gt;
        &amp;lt;/fileset&amp;gt;
        &amp;lt;fileset dir="${build.war.home}/WEB-INF/lib"&amp;gt;
          &amp;lt;include name="*.jar"/&amp;gt;
        &amp;lt;/fileset&amp;gt;
        &amp;lt;pathelement location="/Developer/Java/Ant/lib/ant.jar"/&amp;gt;
      &amp;lt;/classpath&amp;gt;
    &amp;lt;/java&amp;gt;
    &amp;lt;jar jarfile="${build.jar.home}/jsp.jar" basedir="${basedir}/testjsp" 
         includes="**/jsp/**/*.class" 
      /&amp;gt;
  &amp;lt;/target&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
Notice the &lt;strong&gt;second&lt;/strong&gt; &lt;code&gt;&amp;lt;arg&amp;gt;&lt;/code&gt; 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 &lt;em&gt;will&lt;/em&gt; find all the jsps, but it &lt;em&gt;wont&lt;/em&gt; compile them correctly.  It will fail to statically initialize the &lt;code&gt;_jspx_dependants&lt;/code&gt; variable in the generated code.

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


	&lt;p&gt;Anyway, there&amp;#8217;s a new unit test for someone to write.  (sigh).&lt;/p&gt;


	&lt;p&gt;Now I can write my unit test!&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;BTW I&lt;/span&gt; am using Tomcat 5.5.20&lt;/p&gt;</description>
      <pubDate>Thu, 08 Feb 2007 19:29:42 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:17b3cdf9-7800-4896-87cc-4fa92e0470fa</guid>
      <author>Uncle Bob</author>
      <link>http://blog.objectmentor.com/articles/2007/02/08/jasper-problem-resolved</link>
      <category>Uncle Bob's Blatherings</category>
      <trackback:ping>http://blog.objectmentor.com/articles/trackback/151</trackback:ping>
    </item>
  </channel>
</rss>
