写在前面:最近用ANT脚本用的比较的多,发现在ANT中使用条件判断有些麻烦,就查点资料,:(1)可以使用condition进行逻辑的判断,接受的属性是property,相当于boolean xx=true(或false),if,unless相当于if-else.(2)可以使用antcontrib.jar这个包文件,大概看了一下,就是将condition拿掉,使用我们熟悉的if-else-then的结果进行业务逻辑的判断!!
<?xml version="1.0" encoding="UTF-8"?>
<project name="cvs package" basedir="." default="packing_cvs_package.init">
<!--<property name="hello" value="true"/>-->
<!--ant-contrib classpath-->
<input message="Please input the hello name:" addproperty="hello" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="E:/apache-ant-1.8.2/ant-contrib/ant-contrib-1.0b2.jar"/>
</classpath>
</taskdef>
<!--default-->
<target name="packing_cvs_package.init">
<if>
<equals arg1="${hello}" arg2="true"/>
<then>
<echo >${hello} value is true</echo>
</then>
<elseif>
<equals arg1="${hello}" arg2="false"/>
<then>
<echo >${hello} value is false</echo>
</then>
</elseif>
<else>
<echo >${hello} value is unknowe</echo>
</else>
</if>
</target>
</project>
上面的有些路径写绝对路径了,修改下:
<project name="imported" basedir="." default="packing_cvs_package.init">
<dirname property="imported.basedir" file="${ant.file.imported}"/>
<property file="${imported.basedir}/base.properties"/>
<input message="Please input the hello name:" addproperty="hello" />
<!--ant-contrib classpath-->
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${path}"/>
</classpath>
</taskdef>
<!--default-->
<target name="packing_cvs_package.init">
<if>
<equals arg1="${hello}" arg2="true"/>
<then>
<echo >${hello} value is true</echo>
</then>
<elseif>
<equals arg1="${hello}" arg2="false"/>
<then>
<echo >${hello} value is false</echo>
</then>
</elseif>
<else>
<echo >${hello} value is unknowe</echo>
</else>
</if>
</target>
</project>
base.properties文件的内容:
path=E:/apache-ant-1.8.2/ant-contrib/ant-contrib-1.0b2.jar
就是一个地址!!