Changeset 7600


Ignore:
Timestamp:
Feb 22, 2019, 11:16:29 AM (5 years ago)
Author:
Nicklas Nordborg
Message:

References #2151: Pre-compile all JSP pages before releases

Added jsp target to the build-file. tomcat.home must be set and point to a directory with a Tomcat installation that includes the build tools (eg. ${tomcat.home}/bin/catalina-tasks.xml). Note that this is not included in all Tomcat distributions. We recommend using the ZIP file.

We recommend that a build.properties file is created in the root directory and that tomcat.home is set in that file.

The jsp target will load the jsp-precompile.xml file (which is an ant file), and will use <jasper> to pre-compile JSP to java and then a regular <javac> to compile the the java code. The compilation currently generates lots of warnings. The goal is to make them all go away with only Xlint:all,-serial. Currently all,-serial,-unchecked,-rawtypes,-deprecation,-cast is needed which can be specified by setting jsp.xlint in build.properties.

Use the jsp.clean ant target to clean files created by JSP compilation. This is also included in clean but it is typically overkill to have to recompile the entire BASE application.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r7583 r7600  
    7676  <property name="javac.arg" value="-Xlint:all,-varargs"
    7777    description="Extra arguments sent to Java compiler" />
     78  <property name="jsp.xlint" value="all,-serial"
     79    description="Xlint parameter when compiling JSP files (-serial is needed since jasper doesn't generate a serialVersionUID)" />
    7880  <property name="javac.source" value="1.8"
    7981    description="Default value for the 'source' attribute when compiling java code" />
     
    400402    <path id="core.classpath">
    401403      <path refid="lib.dist.classpath" />
    402       <pathelement location="${info.build}" />
    403404    </path>
    404405  </target>
     
    810811  </target>
    811812 
     813  <!-- Targets for JSP precompilation. Useful for checking that eveything works before a release is made. -->
     814  <!-- Use as: 'ant web jsp' to also make sure that dependencies have been compiled -->
    812815  <target
    813     name="web.jsp"
    814     depends="web"
    815     description="Compile all JSP pages to a temporary directory; used for checking only"
    816     >
    817     <property name="jsp.build" location="${build}/jsp" />
    818     <property environment="env" />
    819     <delete dir="${jsp.build}" />
    820     <mkdir dir="${jsp.build}/src" />
    821     <mkdir dir="${jsp.build}/classes" />
    822     <path id="jsp.precompile.classpath">
    823       <pathelement location="${java.home}/../lib/tools.jar" />
    824       <fileset dir="${env.CATALINA_HOME}">
    825         <include name="lib/*.jar" />
    826       </fileset>
    827       <fileset dir="${env.CATALINA_HOME}/bin">
    828         <include name="*.jar" />
    829       </fileset>
    830     </path>
    831    
    832     <path id="jsp.compile.classpath">
    833       <path refid="jsp.precompile.classpath" />
    834       <fileset dir="${web.inf}/lib">
    835         <include name="*.jar" />
    836       </fileset>
    837       <pathelement location="${info.build}" />
    838     </path>
    839 
    840     <taskdef
    841       classname="org.apache.jasper.JspC"
    842       name="jasper2"
    843       classpathref="jsp.precompile.classpath"
    844     />
    845     <jasper2
    846       validateXml="false"
    847       uriroot="www"
    848       webXmlFragment="${jsp.build}/generated_web.xml"
    849       outputdir="${jsp.build}/src"
    850       javaencoding="${javac.encoding}"
    851      
    852     />
    853     <javac
    854       destdir="${jsp.build}/classes"
    855       srcdir="${jsp.build}/src"
    856       debug="true"
    857       classpathref="jsp.compile.classpath"
    858       memoryinitialsize="256m"
    859       memorymaximumsize="512m"
    860       fork="true"
    861       source="${javac.source}"
    862       target="${javac.target}"
    863       encoding="${javac.encoding}"
    864       bootclasspathref="lib.bootclasspath"
    865       includeantruntime="false"
    866       >
    867     </javac>
     816    name="jsp"
     817    depends=""
     818    >
     819    <!-- check that tomcat.home exists and that required the required 'catalina-tasks.xml' is present -->
     820    <fail unless="tomcat.home"
     821      message="{tomcat.home} has not been set. Create 'build.properties' in current directory and add 'tomcat.home' with path to your Tomcat installation directory. " />
     822   
     823    <available file="${tomcat.home}/bin/catalina-tasks.xml" property="catalina-tasks" />
     824   
     825    <fail unless="catalina-tasks"
     826      message="File '${tomcat.home}/bin/catalina-tasks.xml' does not exists. You may have to install this from the Tomcat ZIP distribution." />
     827   
     828    <!-- we are good to go -->
     829    <mkdir dir="${build}/jsp" />
     830    <ant antfile="jsp-precompile.xml" inheritall="false" target="all" >
     831      <property name="tomcat.home" value="${tomcat.home}" />
     832      <property name="jsp.src" value="www" />
     833      <property name="jsp.build" value="${build}/jsp" />
     834      <property name="javac.bootclasspath" value="${javac.bootclasspath}" />
     835      <property name="javac.encoding" value="${javac.encoding}" />
     836      <property name="javac.source" value="${javac.source}" />
     837      <property name="javac.target" value="${javac.target}" />
     838      <property name="jsp.xlint" value="${jsp.xlint}" />
     839    </ant>
     840  </target>
     841 
     842  <!-- Clean up after 'jsp' target -->
     843  <target
     844    name="jsp.clean"
     845    >
     846    <delete dir="${build}/jsp" />
    868847  </target>
    869848 
Note: See TracChangeset for help on using the changeset viewer.