Ant 的常用方法例子

来源:互联网 发布:软件测试缺陷 编辑:程序博客网 时间:2024/05/18 00:20

Ant的常用方法例子

 

1.       javac

 

<path id="base.path">      <pathelement location="${lib.dir}/log4j-1.2.16.jar" /></path><target name="complie"depends="clean">      <javac srcdir="${src.dir}" destdir="${dest.dir}" classpathref="base.path"includeantruntime="on"/>      <echo message="complie source successfully." /></target>


 

2.      Delete, mkdir, and echo

<target name="clean" >                <delete dir="${dest.dir}" />                <delete file="${lib.dir}/safx.jar" />                <mkdir dir="${dest.dir}" />                <echo message="clean and remake classes dir successfully." /></target>


 

3.      Copy

 

<target name="copylog4j"depends="complie">

      <copy todir="${dest.dir}">

            <fileset dir="${src.dir}">

                   <includename="log4j.properties" />           

        </fileset>

        </copy>

        <echo message="copylog4j.properties file successfully." />

</target>


4.      Jar

<target name="jar"depends="copylog4j">          <jar destfile="${lib.dir}/safx.jar" basedir="${dest.dir}" />          <delete dir="${dest.dir}" /></target>

 

5.      Zip

<target name="zip">           <echomessage="zip start..." />           <copy todir="D:/picture">           <fileset dir="${dir.output}"includes="${dir.screenshot}/*.png" />          </copy>           <copy file="log4j_file.html"tofile="${dir.output}/log4j_file.html" />           <zip destfile="${dir.report}/${CREATE_TIME}_${global.browser}_${global.version}.zip"basedir="${dir.output}" includes="*.html"excludes="${dir.screenshot}/*.png" update="true" />           <zipd estfile="${dir.report}/${CREATE_TIME}_${global.browser}_${global.version}_${dir.screenshot}.zip"basedir="${dir.output}" excludes="*.html"includes="${dir.screenshot}/*.png" update="true" />            <echo message="zip end..." /> </target>

 

6.      Email

          

 <targetname="email">         <echo message="email start..." />         <mail mailhost="${mail.host}" mailport="${mail.port}"subject="${CREATE_TIME} The ${global.version} build has completed"ssl="on" charset="utf-8" user="${mail.user}"password="${mail.password}" messagemimetype="text/html">               <from address="${mail.user}" />               <message>The${global.version} build has completed.</message>                                                               <to address="caiqcong@126.com" />                                                               <fileset dir="${dir.report}">                                                                                     <includename="${CREATE_TIME}_${global.browser}_${global.version}.zip" />                                                                                </fileset>          </mail>          <echomessage="email end..." /> </target>


7.      SVNcheckout

<target name="svn.checkout" depends="svn.checkout.prepare">          <echo message="svn.checkout start..." />          <!--svn account and password -->          <svn javahl="true" username="${svn.username}"password="${svn.password}">                <!--SVN server URL -->                <checkouturl="${svn.url}/account" destPath="account"revision="HEAD" />                <checkouturl="${svn.url}/email" destPath="email"revision="HEAD" />                <checkouturl="${svn.url}/import" destPath="import"revision="HEAD" />                                                               <checkouturl="${svn.url}/${svn.dir.schema}"destPath="${svn.dir.schema}" revision="HEAD" />                <checkouturl="${svn.url}/${svn.dir.testCase}/${global.version}"destPath="${svn.dir.testCase}/${global.version}"revision="HEAD" />                <checkouturl="${svn.url}/${svn.dir.webSite}/2.0.24"destPath="${svn.dir.webSite}/2.0.24" revision="HEAD" />           </svn>           <echomessage="svn.checkout end..." /> </target>