[Ant存档] Demonstration Tips of Ant

    技术2022-05-11  128

    <project name="AntTest" default="main" basedir=".">

    <!--     定义path数据类型(datatype),并引用        -->

     <path id="compile.classpath"> <pathelement location="${lucene.jar}"/> <pathelement location="${tidy.jar}"/> </path>  <path id="test.classpath"> <path refid="compile.classpath"/> <pathelement location="${junit.jar}"/> <pathelement location="${build.dir}/classes"/> <pathelement location="${build.dir}/test"/> </path>  <path id="the.path">  <pathelement location="lib/ant.jar"/> </path> <property name="path.string" refid="the.path"/> <echo message="${path.string}"/>

     <!--       引用环境变量        --> <property name="classpath" value="${basedir}/bin"/> <property environment="env." /> <echo message="Number of processors = ${env.NUMBER_OF_PROCESSORS}" /> <echo message="ANT_HOME = ${env.ANT_HOME}"/> <echo message="ITS_HOME = ${env.ITS_HOME}" />  <echo message="Built-in Properties:"/> <echo message="${ant.file}"/> <echo message="${ant.java.version}"/> <echo message="${ant.version}"/>  <property name="build.dir" location="build"/> <echo message="${build.dir}" /> <echo message="${basedir}" /> 

    <!-- demonstrate the immutability of ant's property --> <property file="build.properties"/>  <!--  ought to have an property named build.debug set to off in build.properties file--> <property name="build.debug" value="on"/> <echo message="build.debug = ${build.debug}"/>  <target name="init"> <property name="strip.comment" value="true"/>

    <!-- demonstration of current time -->

        <tstamp>        <format property="TODAY" pattern="yyyy-MM-dd hh:mm aa" />    </tstamp>

    <!-- define self-made tasks --> <taskdef name="simpletask" classname="org.xxx.anttest.SimpleTask" classpath="${classpath}" /> <taskdef name="proctask" classname="org.xxx.anttest.FileProcTask" classpath="${classpath}"/> </target>

    <!-- execute main program with external args -->

     <target name="execute">  <echo level="warning" message="Executing Main Programme..."/>  <java classname="org.xxx.anttest.Test" classpath="bin">   <arg value="first arg"/>   <arg value="second arg"/>   <arg value="third arg"/>  </java> </target>  <target name="simpletask" depends="init" >  <simpletask path="${env.ANT_HOME}:build/output" /> </target>  <target name="proctask" depends="init">  <echo message="Current Time is: ${TODAY}"></echo>  <proctask  dir="${basedir}">   <include name="**/*.java"/>  </proctask> </target> <!--

    1. strip comments in the file of config.properties when copying

    2.  demonstrate the useage of  if  attribute

    -->

     <target name="stripcomment" if="strip.comment" depends="init">  <copy file="config.properties" todir="config">   <filterchain>    <striplinecomments>     <comment value="#"/>    </striplinecomments>   </filterchain>  </copy> </target>

     <target name="main" depends="stripcomment" />

    </project> 


    最新回复(0)