关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、3102411850 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 7712|回复: 0

jsp变为jar包

[复制链接]
发表于 2013-8-2 17:40:05 | 显示全部楼层 |阅读模式
一、ant进行编译处理,构建tomcat6.x以上的build文件
     <?xml version="1.0"?>
<project name="WebApp Precompilation JSP to Java to Class to Jar" basedir="." default="help">  
    <property name="tomcat.home" value="D:/apache-tomcat-6.0.13"/>  
    <property name="webapp.name" value="myapp"/>  
    <property name="webapp.path" value="D:/AntTest/TestHunXiao/WebRoot"/>  
   
   <taskdef resource="proguard/ant/task.properties"
         classpath="D:/AntTest/TestHunXiao/lib/proguard.jar" />
   <proguard configuration="pg.pro"/>
    <target name="all" depends="jsp2java,java2class,class2jar"/>  
    <target name="help">  
        <echo message="显示功能列表"/>  
        <echo message="jsp2java  通过JspCJSP转换成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}/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>  
               
                <fileset dir="${tomcat.home}/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操作
     1.命令: ant all
     2.生成好的jar文件是{$webapp.name}JSP.jar
     3.在做为产品发布的时候,将依赖类包和类jar包和JSP预编译的包放到WEB-INF/lib/  
       目录下即可
     4.然后删除掉你的所有的预编过的JSP源文件
     5.${webapp.path}/WEB-INF/webJSP.xml里的servlet映射,添加到
       ${webapp.path}/WEB-INF/web.xml
     
参考文档:http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/jasper/JspC.html

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表