<project name="test" default="all" basedir=".">
<target name="all"> <antcall target="initialise" /> <antcall target="compile" /> </target>
<target name="initialise" description="Initialise required settings."> <tstamp /> <echo message="Initialization"/> <property name="myProperty" value="toto" /> </target>
<!-- Compile the java code --> <target name="compile" description="Compile ..."> <echo message="Compilation"/> <!-- create a temp build directory --> <mkdir dir="${basedir}/build" /> <!-- compile the source --> <javac srcdir="${basedir}/src" destdir="${basedir}/build"> <classpath refid="build.classpath" /> </javac> </target> </project>
<taskdef name="myTask" classname="my.package.MyClass" />
<taskdef resource="my/package/ant.properties" />
<xslt in="in.xml" style="style.xsl" out="out.html"/>
<style in="in.xml" style="style.xsl" out="out.html"/>
<style processor="trax" in="in.xml" style="style.xsl" out="out.html"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"> <classpath> <pathelement location="/ant-contrib/lib/ant-contrib-x-x.jar"/> </classpath> </taskdef>
<if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is bar" /> </then> <else> <echo message="The value of property foo is not bar" /> </else> </if>
<if> <equals arg1="${foo}" arg2="bar" /> <then> <echo message="The value of property foo is 'bar'" /> </then> <elseif> <equals arg1="${foo}" arg2="foo" /> <then> <echo message="The value of property foo is 'foo'" /> </then> </elseif> <else> <echo message="The value of property foo is not 'foo' or 'bar'"/> </else> </if>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <target name="testForeach1"> <foreach list="toto,titi,tata" param="msg" target="myTask" /> </target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <target name="testForeach2"> <foreach param="msg" target="myTask"> <path> <fileset dir="."> <include name="**/*.xml"/> </fileset> </path> </foreach> </target>
<target name="myTask"> <echo message="${msg}" /> </target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/> <target name="test"> <propertyregex property="pack.name" input="package.ABC.name" regexp="package\.([^\.]*)\.name" select="\1" casesensitive="false" /> <echo>${pack.name}</echo> </target>
Le résultat sera : ABC
<copy file="file.txt" toFile="newFile.txt" />
<copy todir="../new/dir"> <fileset dir="src_dir"/> </copy>
<copy todir="../dest/dir"> <fileset dir="src_dir"> <exclude name="**/*.java"/> </fileset> </copy>
<concat destfile="dest/file.txt"> <fileset dir="source" includes="file-*.txt"/> </concat>
ant -Dsome.prop=value
<echo message="some.prop = ${some.prop}"/>
<property environment="env"/> <echo message="CLASSPATH = ${env.CLASSPATH}"/>
<exec executable="cmd"> <arg line="/c dir"/> </exec>