Ant War 打包

来源:互联网 发布:paparecipe 正品软件 编辑:程序博客网 时间:2024/05/22 15:36

简述:

用ant打包


步骤:

1. 下载ant ,并设置环境变量

http://ant.apache.org/bindownload.cgi


cmd运行ant -version



下面是两种配置(其实是一个意思,无非一个把属性放到了properties文件中)

build.xml 配置

放在项目更路径下

<?xml version="1.0" ?> <project name="WebProj" default="war">     <property name="build.dest" value="build/classes"/>     <path id="compile.classpath"><fileset dir="WebContent/WEB-INF/lib"><include name="*.jar"/></fileset></path><target name="init"><mkdir dir="${build.dest}"/></target><target name="compile" depends="init" ><javac destdir="${build.dest}" debug="true" srcdir="src" encoding="utf-8"><classpath refid="compile.classpath"/></javac></target><target name="copy" depends="compile" description="配置文件拷贝">          <javac srcdir="java/resource" destdir="${build.dest}">              <classpath refid="classpath"/>          </javac>          <copy todir="${build.dest}">              <fileset dir="java/resource">                  <include name="*"/>              </fileset>          </copy>      </target>  <target name="war" depends="copy"><war destfile="WebProj.war" webxml="WebContent/WEB-INF/web.xml"><fileset dir="WebContent"/><lib dir="WebContent/WEB-INF/lib"/><classes dir="${build.dest}"/></war></target><target name="clean"><delete dir="build" /></target></project>


3. 执行cmd: ant 创建war

由于需要额外拷贝 一些配置文件,所以在build中加入了拷贝copy的配置

项目路径如下





build.properties & build.xml  配置

此外如果要单独做一个build.properties文件




build.properties

build.dest=build/classes

build.xml需要引入上面那个build.properties

代码如下:

<?xml version="1.0" ?> <project name="WebProj" default="war"><property file="build.properties" /> <path id="compile.classpath"><fileset dir="WebContent/WEB-INF/lib"><include name="*.jar"/></fileset></path><target name="init"><mkdir dir="${build.dest}"/></target><target name="compile" depends="init" ><javac destdir="${build.dest}" debug="true" srcdir="src" encoding="utf-8"><classpath refid="compile.classpath"/></javac></target><target name="copy" depends="compile" description="配置文件拷贝">          <javac srcdir="java/resource" destdir="${build.dest}">              <classpath refid="classpath"/>          </javac>          <copy todir="${build.dest}">              <fileset dir="java/resource">                  <include name="*"/>              </fileset>          </copy>      </target>  <target name="war" depends="copy"><war destfile="WebProj.war" webxml="WebContent/WEB-INF/web.xml"><fileset dir="WebContent"/><lib dir="WebContent/WEB-INF/lib"/><classes dir="${build.dest}"/></war></target><target name="clean"><delete dir="build" /></target></project>