ant -f build.xml 執行你的build.xml文件
<?xml version = "1.0"?>
<project name = "fax" basedir = "./" default = "start">
<!--使用for循環必需要加上這個-->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<!-- 定義屬性 -->
<var name="targetsource" value="E:/ant/testSourse" />
<var name="source" value="E:/ant/apache-ant-1.9.2" />
<var name="removePath" value="E:/ant/testcode/source.properties" />
<!-- 開始執行的目標-->
<target name="start">
<!-- 獲取當天的時間-->
<tstamp>
<format property="TODAY" pattern="yyyyMMdd"/>
</tstamp>
<!-- 建立測試目錄-->
<antcall target="mkdir" ></antcall>
<!-- 拷貝測試文件-->
<antcall target="copy" ></antcall>
<!-- 刪除測試文件-->
<antcall target="del" ></antcall>
<!-- 壓縮文件文件-->
<antcall target="zip" ></antcall>
<!-- 刪除除了zip外的文件 -->
<delete dir = "${targetsource}/sourse_${TODAY}"></delete>
</target>
<!-- 建立測試目錄-->
<target name="mkdir">
<echo message = "begin mkdir"/>
<mkdir dir="${targetsource}/sourse_${TODAY}" />
<echo message = "end mkdir"/>
</target>
<!-- 拷貝文件及文件夾進行測試-->
<target name="copy">
<echo message = "begin copy"/>
<copy todir="${targetsource}/sourse_${TODAY}" overwrite="true" preservelastmodified="true">
<fileset dir="${source}"/>
</copy>
<copy todir="${targetsource}/sourse_${TODAY}" overwrite="true" preservelastmodified="true">
<fileset dir="E:/ant">
<include name="*.zip"/>
</fileset>
</copy>
<echo message = "end copy"/>
</target>
<!-- 刪除部分文件-->
<target name="del">
<echo message = "begin del"/>
<loadproperties srcFile="${removePath}"/>
<for list="${files}" param="file1">
<sequential>
<delete dir = "${targetsource}/sourse_${TODAY}/@{file1}"> </delete>
</sequential>
</for>
<delete>
<fileset dir = "${targetsource}/sourse_${TODAY}">
<include name = "*.zip"/>
<include name="/apache-ant-1.9.2/**.*"/>
</fileset>
</delete>
<echo message = "end del"/>
</target>
<!-- 壓縮文件-->
<target name="zip">
<!--
destfile 目標文件
duplicate 打包方式(通常使用preserve)
zipfileset 打包那些文件
prefix 增長前綴(使用最佳實踐)
-->
<echo message = "begin zip"/>
<zip destfile="${targetsource}/sourse_${TODAY}.zip" duplicate="preserve" basedir="${targetsource}/sourse_${TODAY}" update="true"/>
<echo message = "end zip"/>
</target>
<!--拷貝ftp上的文件-->
<target name="ftpCopy" description="ftpCopy" >
<echo message = "in ftp server=${server} userid=${userid} password=${password} port=${port} remotedir=${remotedir} "/>
<ftp action="get"
server="${server}"
userid="${userid}"
password="${password}"
port="${port}"
remotedir="${remotedir}" >
<fileset dir="${source}\\NC_HOME_${TODAY}">
<include name="**"/>
</fileset>
</ftp>
</target>
</project>