<?xml version="1.0" encoding="utf8" ?>
<project name="javac" basedir="." default="init">
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<xmlproperty file="script-define.xml" />
<target name="init">
<delete includeEmptyDirs="true">
<fileset dir=".">
<include name="**/*" />
<exclude name="*.xml" />
<exclude name="*.properties" />
<exclude name="*.java" />
</fileset>
</delete>
<mkdir dir="dest" />
<!---->
<javac srcdir="." destdir="." />
<java classname="Hello" classpath="." />
<delete dir="dest" />
<mkdir dir="dest" />
<copy todir="dest" >
<fileset dir=".">
<include name="*.xml" />
</fileset>
</copy>
<zip destfile="hello.zip" >
<fileset dir="." />
</zip>
<for list="a,dfd,fd,fd, df,fdfd,fdd" param="var" trim="true">
<sequential>
<echo message="msg : @{var}" />
</sequential>
</for>
<antcall target="default" />
<for list="${scripts.names}" param="mod" trim="true">
<sequential>
<echo message="name - ${scripts.list.@{mod}.name}, age - ${scripts.list.@{mod}.age}" />
</sequential>
</for>
<tstamp />
<echo message="${DSTAMP}" />
<echo message="${TSTAMP}" />
<echo message="${TODAY}" />
<tstamp>
<format property="now" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="${now}" />
<propertyfile file="hello.txt">
<entry key="msg" value="hello,world"></entry>
<entry key="build.number" default="0001" pattern="0000" type="int" operation="+" />
<entry key="now" type="date" default="now" pattern="yyyy-MM-dd HH:mm:ss" />
</propertyfile>
<record name="dest/log.txt" action="start" />
<javac srcdir="." destdir="." />
<if>
<equals arg1="1" arg2="1" />
<then>
<echo message="if synstax" />
</then>
</if>
<if>
<not>
<equals arg1="2" arg2="1" />
</not>
<then>
<echo message="if not syntax" />
</then>
</if>
<property name="var" value="2" />
<if>
<equals arg1="${var}" arg2="1" />
<then>
<echo message="if syntax : ${var} == 1" />
</then>
<elseif>
<equals arg1="${var}" arg2="2" />
<then>
<echo message="elseif syntax : ${var} == 2" />
</then>
</elseif>
<else>
<echo message="else syntax : var = ${var}" />
</else>
</if>
<ant antfile="build1.xml" target="default" />
<loadproperties srcFile="build.properties" />
<echo message="${msg}" />
<mail mailhost="smtp.126.com" user="ziyunyangyong@126.com" password="xxxxxx" subject="${scripts.mail.subject}">
<from address="ziyunyangyong@126.com"></from>
<to address="ziyunyangyong@126.com" />
<message>${scripts.mail.content}</message>
</mail>
<trycatch property="errorMsg">
<try>
<echo message="try syntax" />
<antcall target="handleSuccess" />
</try>
<catch>
<echo message="catch syntax" />
<antcall target="handleFail" />
</catch>
<finally>
<echo message="finally syntax : ${errorMsg}" />
</finally>
</trycatch>
<replace token="age" value="id">
<fileset dir=".">
<include name="script-define.xml" />
</fileset>
</replace>
</target>
<target name="default">
<echo message="antcall invocation!" />
</target>
<target name="handleSuccess">
<echo message="handle successing" />
<fail>error : handle success</fail>
</target>
<target name="handleFail">
<echo message="handleFail" />
</target>
</project>
ant入门练习脚本
最新推荐文章于 2022-04-12 14:49:26 发布