7.6 Precompiling JSPs for Tomcat 5

This section discusses the Tomcat 5 compiled JSP class file path changes and using Ant to precompile JSP files.

To avoid the delay Tomcat takes to compile and load a JSP file in iManager you can precompile the .jsp file into a Java class file. Deliver the precompiled Java class files with your plug-in and install them to the appropriate Tomcat 5 directory.

7.6.1 Tomcat 5 Compiled Java Class File Location

The Tomcat 5 path for iManager plug-ins is TOMCAT_HOME/work/Catalina/localhost/nps/org/apache. Previously, Tomcat 4 stored iManager plug-ins in TOMCAT_HOME/work/Standalone/localhost/nps. For example:

  • Compiled DeleteClass.jsp path using Tomcat 4: TOMCAT_HOME/work/Standalone/localhost/nps/portal/modules/base/skins/default/devices/default/DeleteClass_jsp.class

  • Compiled DeleteClass.jsp path using Tomcat 5: TOMCAT_HOME/work/Catalina/localhost/nps/org/apache/jsp/portal/modules/base/skins/default_/devices/default_/DeleteClass_jsp.class

To determine the path for a specific JSP class file:

  1. Log into iManager.

  2. Select the task or page that includes the JSP file.

    The first time you access page, Tomcat compiles the JSP into a .java file, then a .class file.

  3. Browse TOMCAT_HOME/work/Catalina/localhost/nps/org/apache/ for the specific class file.

    This is the path you would use when precompiling your JSP.

7.6.2 Precompiling JSP Pages with Ant

The iManager 2.7 build process uses Ant to precompile the JSP files. For information about using Ant to precompile JSPs, see Web Application Compilation in the Tomcat 5 Jasper 2 JSP Engine How To.

Use the sample script found there to pass in the appropriate parameters for TOMCAT_HOME and WEBAPP_PATH and precompile your JSP files. You can modify this script and include in to your build process.

The following examples show an iManager Ant build script and build target. The compiled JSP class files are copied to a working directory and then, later in the build process, zipped up in the .npm file.

IMPORTANT:Because iManager 2.7 plug-ins need to run on NetWare and the 1.4 JDK, you should compile your JSP files with the source and target set to version “1.4” as shown in the above example. This will ensure that the precompiled files will work on all of the iManager 2.7 supported platforms.

Example 7-1 iManager Ant build script named jspc:

 <target name="jspc" depends=".setproperties"> 
   <taskdef classname="org.apache.jasper.JspC" name="jasper2" > 
     <classpath id="jspc.classpath">
       <pathelement location="${java.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 
     webXml="${webapp.path}/WEB-INF/web.xml"
     validateXml="false" 
         uriroot="${webapp.path}"
         webXmlFragment="${webapp.path}/WEB-INF/generated_web.xml"
     outputDir="${webapp.path}/WEB-INF/work/Catalina/localhost/${Product.Name}"/>
 </target>
 

Example 7-2 iManager Ant build target named compilejsps.

 <target name="compilejsps" depends="jspc">
   <javac destdir="${webapp.path}/WEB-INF/classes"
         optimize="off"
     source="1.4"
     target="1.4"
         debug="on" 
     failonerror="false"
         srcdir="${webapp.path}/WEB-INF/work/" 
     excludes="**/*.smap">
     <classpath>
       <pathelement location="${webapp.path}/WEB-INF/classes/org"/>
       <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>
           <fileset dir="${tomcat.home}/bin"> 
               <include name="*.jar"/> 
           </fileset> 
     </classpath>
       <include name="**" />
           <exclude name="tags/**" />
   </javac>
   <copy preservelastmodified="yes" todir="${webapp.path}/WEB-INF/work/Catalina/localhost/nps/org" >
     <fileset dir="${webapp.path}/WEB-INF/classes/org" />
   </copy>
 </target>