前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Tomcat中JSP预编译处理Jasper 2 JSP Engine

Tomcat中JSP预编译处理Jasper 2 JSP Engine

作者头像
阿敏总司令
发布2019-02-28 14:38:44
2.5K0
发布2019-02-28 14:38:44
举报
文章被收录于专栏:简单就是美!简单就是美!

阅读更多

参考:

The Apache Jakarta Tomcat 5.5 Servlet/JSP Container Jasper 2 JSP Engine How To

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jasper-howto.html

jspc

http://ant.apache.org/manual/OptionalTasks/jspc.html

用Tomcat进行预编译的ant脚本如下:

build.properties的内容为:

tomcat.home=E:/OpenSource/Tomcat webapp.name=webappname webapp.path=E:/JavaProject/webappname

build.xml的内容为:

<!----><!----><?xml version="1.0" encoding="GBK"?> <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>

只需要设置好Ant的path环境变量,然后修改build.properties。执行ant all命令即可。 生成好的jar文件是{$webappname}JSP.jar。 在做为产品发布的时候,只需要你的类jar包和JSP预编译的包放到WEB-INF\lib\目录下即可,如${webappname}.jar和JSP预编译的包${webappname}JSP.jar; 然后删除掉你的所有的预编过的JSP源文件; 并且${webapp.path}/WEB-INF/webJSP.xml里的servlet映射,添加到${webapp.path}/WEB-INF/web.xml中。

这里有个问题,不知道有没有办法帮我们直接添加到我们已经存在的web.xml里,想偷个懒啊。。。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2005-06-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档