Tomcat JSPプリコンパイル
19523 ワード
- 1. build.properties
- tomcat.home=D:/Tomcat/apache-tomcat-7.0.14
- java.home=D:/Program Files/Java/jdk1.6.0_25
- webapp.name=Test
- webapp.path=E/:/WorkSpace/MyEclipse9.0/Test/WebRoot
- 2. Ant build.xml
- Tomcat6.X
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="WebApp Precompilation JSP to Java to Class to Jar" basedir="." default="help">
- <property file="build.properties" />
- <target name="all" depends="jsp2java,java2class,class2jar,clear" />
- <target name="help">
- <echo message=" " />
- <echo message="jsp2java JspC JSP Java " />
- <echo message="java2class Java class " />
- <echo message="class2jar class " />
- <echo message="clear " />
- </target>
- <target name="jsp2java">
- <taskdef classname="org.apache.jasper.JspC" name="jsp2java">
- <classpath id="jsp2java.classpath">
- <fileset dir="${tomcat.home}/bin">
- <include name="*.jar" />
- </fileset>
- <fileset dir="${tomcat.home}/lib">
- <include name="*.jar" />
- </fileset>
- </classpath>
- </taskdef>
- <!-- JSP UTF-8 -->
- <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" />
- </target>
- <target name="java2class">
- <mkdir dir="${webapp.path}/WEB-INF/JspC/classes" />
- <!-- Java UTF-8 -->
- <javac srcdir="${webapp.path}/../src" destdir="${webapp.path}/WEB-INF/JspC/classes" encoding="UTF-8" optimize="off" debug="on" failonerror="false" excludes="**/*.smap">
- <classpath id="java2class.classpath">
- <pathelement location="${webapp.path}/WEB-INF/classes" />
- <fileset dir="${webapp.path}/WEB-INF/lib">
- <include name="*.jar" />
- </fileset>
- <fileset dir="${tomcat.home}/bin">
- <include name="*.jar" />
- </fileset>
- </classpath>
- <include name="**" />
- <exclude name="tags/**" />
- </javac>
- </target>
- <target name="class2jar">
- <mkdir dir="${webapp.path}/WEB-INF/lib" />
- <jar basedir="${webapp.path}/WEB-INF/JspC/classes" jarfile="${webapp.path}/WEB-INF/lib/${webapp.name}JSP.jar" />
- </target>
- <target name="clear">
- <delete dir="${webapp.path}/WEB-INF/JspC/classes" />
- <delete dir="${webapp.path}/WEB-INF/JspC/src" />
- <delete dir="${webapp.path}/WEB-INF/JspC" />
- </target>
- </project>
- Tomcat5.5
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="WebApp Precompilation JSP to Java to Class to Jar" basedir="." default="help">
- <property file="build.properties" />
- <target name="all" depends="jsp2java,java2class,class2jar,clear" />
- <target name="help">
- <echo message=" " />
- <echo message="jsp2java JspC JSP Java " />
- <echo message="java2class Java class " />
- <echo message="class2jar class " />
- <echo message="clear " />
- </target>
- <target name="jsp2java">
- <taskdef classname="org.apache.jasper.JspC" name="jsp2java">
- <classpath id="jsp2java.classpath">
- <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>
- <!-- JSP UTF-8 -->
- <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" />
- </target>
- <target name="java2class">
- <mkdir dir="${webapp.path}/WEB-INF/JspC/classes" />
- <!-- Java UTF-8 -->
- <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">
- <classpath id="java2class.classpath">
- <pathelement location="${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>
- <fileset dir="${tomcat.home}/bin">
- <include name="*.jar" />
- </fileset>
- </classpath>
- <include name="**" />
- <exclude name="tags/**" />
- </javac>
- </target>
- <target name="class2jar">
- <mkdir dir="${webapp.path}/WEB-INF/lib" />
- <jar basedir="${webapp.path}/WEB-INF/JspC/classes" jarfile="${webapp.path}/WEB-INF/lib/${webapp.name}JSP.jar" />
- </target>
- <target name="clear">
- <delete dir="${webapp.path}/WEB-INF/JspC/classes" />
- <delete dir="${webapp.path}/WEB-INF/JspC/src" />
- <delete dir="${webapp.path}/WEB-INF/JspC" />
- </target>
- </project>
- 3. Ant path ,
- 4. build.properties,
- 5. ant all 。
- 6. jar {$webappname}JSP.jar。
- 7. , jar JSP WEB-INF/lib/ ;
- 8. JSP ;
- 9. ${webapp.path}/WEB-INF/webJSP.xml servlet , ${webapp.path}/WEB-INF/web.xml 。
- : MyEclipse Ant , JDK JAVE_HOME JDK
- :
- http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html
- http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/jasper/JspC.html
- http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/jasper/JspC.html