ant入门练习脚本

<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值