Tomcat JSPプリコンパイル



  
  
  
  
  1. 1.  build.properties 
  2. tomcat.home=D:/Tomcat/apache-tomcat-7.0.14 
  3. java.home=D:/Program Files/Java/jdk1.6.0_25 
  4. webapp.name=Test 
  5. webapp.path=E/:/WorkSpace/MyEclipse9.0/Test/WebRoot 
  6. 2. Ant build.xml 
  7. Tomcat6.X  
  8. <?xml version="1.0" encoding="UTF-8"?> 
  9. <project name="WebApp Precompilation JSP to Java to Class to Jar" basedir="." default="help"
  10.     <property file="build.properties" /> 
  11.     <target name="all" depends="jsp2java,java2class,class2jar,clear" /> 
  12.     <target name="help"
  13.         <echo message=" " /> 
  14.         <echo message="jsp2java   JspC JSP Java " /> 
  15.         <echo message="java2class  Java class " /> 
  16.         <echo message="class2jar  class " /> 
  17.         <echo message="clear   " /> 
  18.     </target> 
  19.     <target name="jsp2java"
  20.         <taskdef classname="org.apache.jasper.JspC" name="jsp2java"
  21.             <classpath id="jsp2java.classpath"
  22.                 <fileset dir="${tomcat.home}/bin"
  23.                     <include name="*.jar" /> 
  24.                 </fileset> 
  25.                 <fileset dir="${tomcat.home}/lib"
  26.                     <include name="*.jar" /> 
  27.                 </fileset> 
  28.             </classpath> 
  29.         </taskdef> 
  30.         <!--  JSP UTF-8  --> 
  31.         <jsp2java classpath="jsp2java.classpath" javaEncoding="UTF-8" validateXml="false" uriroot="${webapp.path}" webXmlFragment="${webapp.path}/WEB-INF/webJSP.xml" outputDir="${webapp.path}/WEB-INF/JspC/src" /> 
  32.     </target> 
  33.     <target name="java2class"
  34.         <mkdir dir="${webapp.path}/WEB-INF/JspC/classes" /> 
  35.         <!--  Java UTF-8  --> 
  36.         <javac srcdir="${webapp.path}/../src" destdir="${webapp.path}/WEB-INF/JspC/classes" encoding="UTF-8" optimize="off" debug="on" failonerror="false" excludes="**/*.smap"
  37.             <classpath id="java2class.classpath"
  38.                 <pathelement location="${webapp.path}/WEB-INF/classes" /> 
  39.                 <fileset dir="${webapp.path}/WEB-INF/lib"
  40.                     <include name="*.jar" /> 
  41.                 </fileset> 
  42.                 <fileset dir="${tomcat.home}/bin"
  43.                     <include name="*.jar" /> 
  44.                 </fileset> 
  45.             </classpath> 
  46.             <include name="**" /> 
  47.             <exclude name="tags/**" /> 
  48.         </javac> 
  49.     </target> 
  50.     <target name="class2jar"
  51.         <mkdir dir="${webapp.path}/WEB-INF/lib" /> 
  52.         <jar basedir="${webapp.path}/WEB-INF/JspC/classes" jarfile="${webapp.path}/WEB-INF/lib/${webapp.name}JSP.jar" /> 
  53.     </target> 
  54.     <target name="clear"
  55.         <delete dir="${webapp.path}/WEB-INF/JspC/classes" /> 
  56.         <delete dir="${webapp.path}/WEB-INF/JspC/src" /> 
  57.         <delete dir="${webapp.path}/WEB-INF/JspC" /> 
  58.     </target> 
  59. </project> 
  60. Tomcat5.5  
  61. <?xml version="1.0" encoding="UTF-8"?> 
  62. <project name="WebApp Precompilation JSP to Java to Class to Jar" basedir="." default="help"
  63.     <property file="build.properties" /> 
  64.     <target name="all" depends="jsp2java,java2class,class2jar,clear" /> 
  65.     <target name="help"
  66.         <echo message=" " /> 
  67.         <echo message="jsp2java   JspC JSP Java " /> 
  68.         <echo message="java2class  Java class " /> 
  69.         <echo message="class2jar  class " /> 
  70.         <echo message="clear   " /> 
  71.     </target> 
  72.     <target name="jsp2java"
  73.         <taskdef classname="org.apache.jasper.JspC" name="jsp2java"
  74.             <classpath id="jsp2java.classpath"
  75.                 <fileset dir="${tomcat.home}/bin"
  76.                     <include name="*.jar" /> 
  77.                 </fileset> 
  78.                 <fileset dir="${tomcat.home}/server/lib"
  79.                     <include name="*.jar" /> 
  80.                 </fileset> 
  81.                 <fileset dir="${tomcat.home}/common/lib"
  82.                     <include name="*.jar" /> 
  83.                 </fileset> 
  84.             </classpath> 
  85.         </taskdef> 
  86.         <!--  JSP UTF-8  --> 
  87.         <jsp2java classpath="jsp2java.classpath" javaEncoding="UTF-8" validateXml="false" uriroot="${webapp.path}" webXmlFragment="${webapp.path}/WEB-INF/webJSP.xml" outputDir="${webapp.path}/WEB-INF/JspC/src" /> 
  88.     </target> 
  89.     <target name="java2class"
  90.         <mkdir dir="${webapp.path}/WEB-INF/JspC/classes" /> 
  91.         <!--  Java UTF-8  --> 
  92.         <javac srcdir="${webapp.path}/WEB-INF/JspC/src" destdir="${webapp.path}/WEB-INF/JspC/classes" encoding="UTF-8" optimize="off" debug="on" failonerror="false" excludes="**/*.smap"
  93.             <classpath id="java2class.classpath"
  94.                 <pathelement location="${webapp.path}/WEB-INF/classes" /> 
  95.                 <fileset dir="${webapp.path}/WEB-INF/lib"
  96.                     <include name="*.jar" /> 
  97.                 </fileset> 
  98.                 <pathelement location="${tomcat.home}/common/classes" /> 
  99.                 <fileset dir="${tomcat.home}/common/lib"
  100.                     <include name="*.jar" /> 
  101.                 </fileset> 
  102.                 <pathelement location="${tomcat.home}/shared/classes" /> 
  103.                 <fileset dir="${tomcat.home}/shared/lib"
  104.                     <include name="*.jar" /> 
  105.                 </fileset> 
  106.                 <fileset dir="${tomcat.home}/bin"
  107.                     <include name="*.jar" /> 
  108.                 </fileset> 
  109.             </classpath> 
  110.             <include name="**" /> 
  111.             <exclude name="tags/**" /> 
  112.         </javac> 
  113.     </target> 
  114.     <target name="class2jar"
  115.         <mkdir dir="${webapp.path}/WEB-INF/lib" /> 
  116.         <jar basedir="${webapp.path}/WEB-INF/JspC/classes" jarfile="${webapp.path}/WEB-INF/lib/${webapp.name}JSP.jar" /> 
  117.     </target> 
  118.     <target name="clear"
  119.         <delete dir="${webapp.path}/WEB-INF/JspC/classes" /> 
  120.         <delete dir="${webapp.path}/WEB-INF/JspC/src" /> 
  121.         <delete dir="${webapp.path}/WEB-INF/JspC" /> 
  122.     </target> 
  123. </project> 
  124. 3.  Ant path , 
  125. 4.  build.properties, 
  126. 5.  ant all 。 
  127. 6.  jar {$webappname}JSP.jar。 
  128. 7.  , jar JSP WEB-INF/lib/ ; 
  129. 8.  JSP ; 
  130. 9.  ${webapp.path}/WEB-INF/webJSP.xml servlet , ${webapp.path}/WEB-INF/web.xml 。 
  131. : MyEclipse Ant , JDK JAVE_HOME JDK  
  132. : 
  133. http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html 
  134. http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/jasper/JspC.html 
  135. http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/jasper/JspC.html