Ant配置文件build.xml

本文介绍了一种使用Ant脚本实现的JSP预编译构建流程,包括JSP到Java源代码的转换、Java源代码的编译、编译后的Class文件打包成Jar的过程。该流程利用了JspC工具进行JSP文件到Java文件的转换,并确保所有文件采用UTF-8编码。同时,还详细配置了编译和打包过程中所需的类路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?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 memorymaximumsize="500M" fork="true" 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>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值