Precompile JSPs

From Null-pointer

Jump to: navigation, search

To precompile JSP files using Tomcat. This is helpful for when testing a failed precompile on the Portal deployment.

Example jspc.xml

<project name="Webapp Precompilation" default="all" basedir="."> 
	<property name="tomcat.home" value="C:\devapps\apache-tomcat-5.5.20" />
	<property name="webapp.path"  value="temp" />

<target name="jspc"> 

    <taskdef classname="org.apache.jasper.JspC" name="jasper2" > 
      <classpath id="jspc.classpath"> 
        <pathelement location="${tomcat.home}\lib\tools.jar"/> 
        <fileset dir="${tomcat.home}\bin"> 
          <include name="*.jar"/> 
        </fileset> 
        <fileset dir="${tomcat.home}\server\lib"> 
          <include name="*.jar"/> 
        </fileset> 
        <fileset dir="${tomcat.home}\common\lib"> 
          <include name="*.jar"/> 
        </fileset>  

      </classpath> 
    </taskdef>  

    <jasper2 
             validateXml="false" 
             uriroot="${webapp.path}" 
             webXmlFragment="${webapp.path}\WEB-INF\web.xml.dev" 
             outputDir="${webapp.path}\src" />    

</target>  

<target name="compile"> 
  .     <mkdir dir="${webapp.path}\WEB-INF\classes"/>

    <javac destdir="${webapp.path}\WEB-INF\classes"
           optimize="off"
           debug="on" failonerror="false"
           srcdir="${webapp.path}\src"  
	   excludes="**/*.smap" >
      <classpath>
       <pathelement location="C${webapp.path}\WEB-INF\classes"/>
       <fileset dir="${webapp.path}\WEB-INF\lib">
         <include name="*.jar"/>
       </fileset>
       <pathelement location="${tomcat.home}\common\classes"/>
       <fileset dir="${tomcat.home}\common\lib">
         <include name="*.jar"/>
       </fileset>
       <pathelement location="${tomcat.home}\shared\classes"/>
       <fileset dir="${tomcat.home}\shared\lib">
         <include name="*.jar"/>
       </fileset>
     </classpath>
     <include name="**" />
     <exclude name="tags/**" />
   </javac>

  </target>

  <target name="all" depends="jspc,compile">
  </target>

 <target name="clean">
 	<delete dir="${webapp.path}" />
 </target>

 <target name="unzip" depends="clean">
   <mkdir dir="${webapp.path}"/>
   <unzip encoding="ASCII" src="myapplication.war" dest="${webapp.path}"/>
 </target>
</project>

Building

ant -f jspf.xml unzip, all
ant -f jspf.xml unzip
ant -f jspf.xml
ant -f jspf.xml clean

See Also

Personal tools