Ant DataType 小结:
<?xml version="1.0" encoding="UTF-8"?> <project name="build" basedir="."> <property name="src.dir" value="src"/> <property name="doc.dir" value="doc"/> <target name="javadoc"> <delete dir="build"/> <delete dir="${doc.dir}"/> <mkdir dir="${doc.dir}"/> <javadoc encoding="GBK" docencoding="GBK" destdir="${doc.dir}"> <fileset dir="${src.dir}"> </fileset> </javadoc> </target> <target name="copyfile"> <copy todir="build1"> <fileset dir="."> <include name="*.xml"/> </fileset> </copy> </target> <path id="project.class.path"> <pathelement location="bin"/> <pathelement location="*.jar"/> </path> <!-- argument demo --> <target name="argDemo"> <java fork="true" classname="hello.AntMain" failοnerrοr="true"> <arg line="shi jie"/> <arg path="/temp;"/> <arg path="/temp"/> <arg value="-IN hello world -IN people -OUT outed"/> <classpath refid="project.class.path"/> </java> </target> <!-- environment demo --> <target name="envDemo" depends="checkHome"> <property environment="env"/> <echo message="${env.MY_HOME}"/> </target> <target name="checkHome" unless="env.MY_HOME"> <fail message="MY_HOME must be set!"/> </target> <!-- fileset demo --> <property name="build.dist" value="dist"/> <target name="filesetDemo"> <delete dir="${build.dist}"/> <mkdir dir="${build.dist}"/> <copy todir="${build.dist}"> <fileset dir="."> <patternset refid="pn2"/> </fileset> </copy> </target> <patternset id="pn2"> <include name="*.xml"/> </patternset> <!-- patternset demo --> <property name="build.dir" value="build"/> <target name="prepare"> <delete dir="${build.dir}"/> <mkdir dir="${build.dir}"/> <mkdir dir="${build.dir}/classes"/> </target> <target name="compile1" depends="prepare"> <javac destdir="${build.dir}/classes"> <src path="${src.dir}"/> <patternset refid="pnCom1"/> </javac> </target> <patternset id="pnCom1"> <include name="**" unless="PG.java"/> </patternset> <!-- tokenFilter demo --> <target name="tokenFilterDemo"> <tstamp> <format property="now" pattern="yyyy MM dd hh:mm:ss"/> </tstamp> <copy todir="${build.dir}" filtering="true"> <fileset dir="${src.dir}"> <include name="**/*.java"/> </fileset> <!-- search %BUILD_DATE! %COPYRIGHT! --> <filterset begintoken="%" endtoken="!"> <filter token="BUILD_DATE" value="${now}"/> <filter token="COPYRIGHT" value="Copyright (C) 2002 O'Reilly"/> </filterset> </copy> </target> <!-- path demo --> <target name="pathDemo"> <path id="clsPath"> <fileset dir="${src.lib}" includes="*.jar"/> </path> </target> <!-- glob mapper demo --> <mapper id="backManager" type="glob" from="*.java" to="*.java.bkb"/> <mapper id="mpr1" type="identity"/> <mapper id="mpr2" type="flatten"/> <!-- 此时from属性被付略,将原文件名和to属性制定的相匹配 --> <mapper id="mpr3" type="merge" to="oreilly.zip"/> <target name="prepare1"> <delete dir="${build.dir}/bkb"/> <mkdir dir="${build.dir}/bkb"/> </target> <target name="backupFiles" depends="prepare1"> <copy todir="${build.dir}/bkb"> <fileset dir="${src.dir}" includes="**/*.java"/> <mapper refid="mpr3"/> </copy> </target> </project>