2 Replies Latest reply on Mar 16, 2004 5:47 PM by jae77

    Ack, jspf files don't precompile!  Please help!

    shinysteelrobot

      JSP fragment files (*.jspf) don't seem to be precompilable. I've set up a "precompile" target in my Ant build script. It invokes jspc which works fine for .jsp files. The .jsp files get compiled, war'red, and run within JBoss 3.0.8. However, the jspf files DO NOT get compiled by the jspc task. This is a big problem as a lot of my code is in jspf files.

      The weird thing is that the jspf and jsp files both work fine when accessed/compiled within a running version JBoss. So somehow JBoss is able to compile jspf files with no problem. Why doesn't it work for jspc?

      I'm attaching my "precompile" ant target below in case anyone spots an obvious error in it (I couldn't get the Ant variable dollarsign-curly brace stuff to show up correctly though, so all the variable assignments look like empty strings, "").

      Many thanks for any help!

      - Justin

      <target name="precompile" depends="init" description="Precompile JSPs in WAR">
       <echo message="Started JSP precompilation"/>
       <echo message="set precompilation properties"/>
       <property name="jasper.jar" value="/server/default/deploy/jbossweb.sar/org.apache.jasper.jar"/>
       <property name="servlet.jar" value="/server/default/deploy/jbossweb.sar/org.mortbay.jetty.jar"/>
       <property name="jsp.precomp.unwarred_pweb_tmpdir" value="/pweb2_unwar"/>
       <property name="jsp.precomp.generated_java_tmpdir" value="/generated_java"/>
       <property name="jsp.precomp.generated_servlets_xml_file" value="/WEB-INF/jsp-servlets.xml"/>
      
       <echo message="set precompilation classpath"/>
       <path id="jsp.precomp.classpath">
       <pathelement location=""/>
       <pathelement location=""/>
       <pathelement location="/j2ee.jar"/>
       <pathelement location="/crimson.jar"/>
       <pathelement location="/log4j.jar"/>
       <pathelement location="/wm-jam-common.jar"/>
       </path>
      
       <echo message="delete and re-create precompilation directories"/>
       <delete dir=""/>
       <delete dir=""/>
       <mkdir dir=""/>
      
       <echo message="unwar WAR file from src () to dest ()"/>
       <unwar src="" dest=""/>
      
       <echo message="translate JSP files to Java source code"/>
       <jspc
       failonerror="false"
       srcdir=""
       destdir=""
       verbose="3"
       compiler="jasper41"
       webinc="">
       <classpath>
       <pathelement location="/WEB-INF/classes"/>
       <fileset dir="/WEB-INF/lib"><include name="*.jar"/></fileset>
       <path refid="jsp.precomp.classpath"/>
       </classpath>
       </jspc>
      
       <echo message="precompile the translated JSP-Java files to class binaries"/>
       <javac
       srcdir=""
       destdir="/WEB-INF/classes"
       optimize=""
       debug=""
       depend=""
       verbose=""
       deprecation=""
       includeAntRuntime=""
       includeJavaRuntime=""
       failonerror="false">
       <classpath>
       <pathelement location="/WEB-INF/classes"/>
       <fileset dir="/WEB-INF/lib"><include name="*.jar"/></fileset>
       <path refid="jsp.precomp.classpath"/>
       </classpath>
       <include name="**/*.java"/>
       </javac>
      
       <echo message="merge newly compiled JSP-Java servlet directives into web.xml"/>
       <loadfile property="directives" srcFile=""/>
       <replace file="/WEB-INF/web.xml" value="" token="<!-- precompilation merge-point -->"/>
      
      <!--
       <echo message="removing JSPs from webapp since they are now compiled servlets"/>
       <delete>
       <fileset dir="">
       <include name="**/*.jsp"/>
       </fileset>
       </delete>
      -->
       <echo message="re-war tmp webapp dir from src () to dest ()"/>
       <jar destfile="/pweb.war" basedir=""/>
      
       <!-- tidy up working directories
       <delete dir=""/>
       <delete dir=""/> not yet!-->
      
       <echo message="Finished JSP precompilation"/>
       </target>
      


        • 1. Re: Ack, jspf files don't precompile!  Please help!
          shinysteelrobot

          Following up to my own post in case anyone else has the same problem:

          I looked at the source code for the precompiler in the Tomcat/Jasper source distribution. Specifically, I looked at the JspC code that's used by Ant's jspc task. Although the extensions instance variable is defined as a Vector, it turns out that JspC *hardcodes* the string "jsp" file as the one and only entry(!), and you can't modify it (there is no command-line argument to set the extensions, and the extensions member variable is not public--it should probably be public static). Doh!

          To paraphrase my dog-training friend, "Bad programmer, no cookie."

          Fortunately, JspC *does* accept a list of files that can be passed in as arguments after all the other "regular" arguments have been processed. Now all I have to do is build that list of *.jsp and *.jspf files within an ant task and pass them in to JspC.

          • 2. Re: Ack, jspf files don't precompile!  Please help!
            jae77

            also be aware that jspc has a limitation on the number of files it can accept to pre-compile.

            if you have a lot of jsps, you may need to process them in "batches".

            [disclaimer] this is the behavior i experience trying to compile 300+ jsps, so it's possible that i'm incorrect w/ the above statement.