Simple Demo

<?xml version="1.0" encoding="UTF-8"?> <project name="HelloWorld" default="run" basedir="."> <!-- global vars --> <property name="src" value="src"/> <property name="dest" value="classes"/> <property name="hello_jar" value="hello1.jar"/> <!-- prepare deploying dir structure --> <target name="init"> <mkdir dir="${dest}"/> </target> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${dest}"/> </target> <target name="build" depends="compile"> <jar jarfile="${hello_jar}" basedir="${dest}"/> </target> <target name="run" depends="build"> <java classname="test.ant.HelloWorld" classpath="${hello_jar}"/> </target> <target name="clean"> <delete dir="${dest}"/> <delete dir="${hello_jar}"/> </target> <!-- demonstrate target dependencies --> <target name="rerun" depends="clean,run"> <ant target="clean"/> <ant target="run"/> </target> </project>

● 每个buildfile包含一个project和N个target(N≥1)。
● 每个target包含多个task元素。
● 每个task元素有一个唯一的ID。<taskname id="taskID" ... />

<project name="Demo" default="dist" basedir="."> <!-- name default basedir 都是project的attribute --> <description> This buildfile is used to build the Foo subproject within the large, complex Demo project. </description> <!-- set global properties for this build --> ......

● 从Ant 1.6开始,所有的task都可以在target外面进行声明。也就是说,在任何target还没有执行前,这些task就已经计算过了。所以,如果脚本写得不仔细的话,有可能出现无限循环。比如使用了antcall。


● 给target加上description,那么用projecthelp时,就会把该target作为public target而列给用户看。

<target name="cpy" depends="init" description="copy all res to working dir.">

● filtering copy

<filter token="year" value="2000"/> <copy todir="${dest}" filtering="true"> <fileset dir="${src.dir}"/> </copy>

● target运行条件if/unless如果要检查多项,那么可以把这些东西统一到一个独立的target里:

<target name="target.check"> <condition property="foobar.exist"> <and> <available file="${src}/foo.txt"/> <available file="${src}/bar.txt"/> </and> </condition> </target> <target name="run" depends="target.check" if="foobar.exist"> <echo>Files foo.txt and bar.txt are present.</echo> </target>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值