以下脚本来自Ant官方文档:
number1:
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
number2:
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="run" basedir=".">
<property name = "src" value = "src"/>
<property name = "dest" value = "classes"/>
<property name = "hello_jar" value = "hello1.jar"/>
<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>
<target name="rerun" depends = "clean,run">
<ant target = "clean"/>
<ant target = "run"/>
</target>
</project>
number3:
<project name="MyProject" default="myTarget" basedir=".">
<target name="myTarget" depends="myTarget.check" if="myTarget.run">
<echo>Files a.txt and b.txt are present.</echo>
</target>
<target name="myTarget.check">
<condition property="myTarget.run">
<and>
<available file="a.txt"/>
<available file="b.txt"/>
</and>
</condition>
</target>
</project>
number4:
<project name="HelloWorld" default="lots-of-stuff" basedir=".">
<target name="-check-use-file">
<available property="file.exists" file="some-file"/>
</target>
<target name="use-file" depends="-check-use-file" if="file.exists">
<!-- do something requiring that file... -->
</target>
<target name="lots-of-stuff" depends="use-file,other-unconditional-stuff">
</target>
</project>
number5:
<property file="my-prefs.properties"/>
<target name="print-message" unless="${skip.printing.message}">
<echo>hello!</echo>
</target>
number6:
<target name="-check-use-file" unless="file.exists">
<available property="file.exists" file="some-file"/>
</target>
<target name="use-file" depends="-check-use-file" if="${file.exists}">
<!-- do something requiring that file... -->
</target>
<target name="lots-of-stuff" depends="use-file,other-unconditional-stuff"/>
number7:
<project default = "help">
<property name = "db.user" value = "wangbisheng"/>
<target name = "Input">
<input
message = "Please enter db-username: "
addproperty = "db.user"
defaultvalue = "Scott-Tiger"
/>
<echo>"${db.user}"</echo>
</target>
<target name = "help">
<java classname = "myname" classpath = "."/>
</target>
</project>