ant的构建入门(二)

学习学习公司一个牛人写的build.xml文件

<project name="MyProject" default="compile" basedir=".">
<!-- set global properties for this build -->
<property name="project" value="ipcamera"/>
<property name="src" location="src"/>
<property name="web" location="WebRoot"/>
<property name="web-lib" location="${web}/WEB-INF/lib"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="lib-compile" location="lib"/>

<path id="classpath.compile">
       <fileset dir="${web-lib}">
         <include name="**/*.jar"/>
       </fileset>
       <fileset dir="${lib-compile}">
         <include name="**/*.jar"/>
       </fileset>
       <pathelement path="${build}"/>
</path>
 
    <target name="init">
     <!-- Create the build directory structure used by compile -->
     <mkdir dir="${build}"/>
     <mkdir dir="${dist}"/>
</target>

<target name="compile" depends="init" description="compile the source" >
<mkdir dir="${build}/classes"/>
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}/classes" debug="true" deprecation="true" optimize="false" failonerror="true" encoding="utf-8">
     <classpath refid="classpath.compile"/>
    </javac>
</target>

<target name="copyWebFiles" depends="compile">
    <mkdir dir="${build}/web"/>
<copy todir="${build}/web">
   <fileset dir="${web}" excludes="WEB-INF/classes/">
   </fileset>
</copy>
<copy todir="${build}/web/WEB-INF/classes">
   <fileset dir="${build}/classes">
   </fileset>
   <fileset dir="${src}">
    <exclude name="**/*.java"/>
    <exclude name="ipcamera.properties"/>
    <exclude name="ipcamera.properties.*"/>
   </fileset>
</copy>
</target>

<target name="config4debug">
   <copy file="${src}/ipcamera.properties" tofile="${dist}/ipcamera.properties"/>
</target>

<target name="config4release">
   <copy file="${src}/ipcamera.properties.prod" tofile="${dist}/ipcamera.properties"/>
</target>

<target name="config4test">
   <copy file="${src}/ipcamera.properties.test" tofile="${dist}/ipcamera.properties"/>
</target>

<target name="config4beta">
   <copy file="${src}/ipcamera.properties.beta" tofile="${dist}/ipcamera.properties"/>
</target>

<target name="buildWar">
<mkdir dir="${dist}"/>
<war destfile="${dist}/${project}.war" webxml="${build}/web/WEB-INF/web.xml">
   <fileset dir="${build}/web"/>
</war>
</target>

<target name="jarWebServices">
   <jar destfile="${dist}/webservices-interface.jar" basedir="${build}/classes" includes="com/megaeyes/ipcamera/service/webservice/**" excludes="com/megaeyes/ipcamera/service/webservice/impl/**,com/megaeyes/ipcamera/service/webservice/tools/**"/>
</target>

<target name="zipWeb">
   <zip destfile="${dist}/web.zip" basedir="pages" excludes="demo/**"/>  
</target>

<target name="war" depends="clean,copyWebFiles,config4debug,buildWar,zipWeb" description="generate the war package for personal debug" >
</target>

<target name="release" depends="clean,copyWebFiles,config4release,buildWar,zipWeb" description="generate the war package for release" >
</target>

<target name="intTest" depends="clean,copyWebFiles,config4test,buildWar,zipWeb" description="generate the war package for integration test" >
</target>

<target name="beta" depends="clean,copyWebFiles,config4beta,buildWar,zipWeb" description="generate the war package for integration test" >
</target>

<target name="clean" description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
</target>

</project>

你可能感兴趣的:(java,xml,ant)