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>