在ant中处理逻辑判断真是麻烦,只能作用于task,要利用property来做判断,使用available来设置property。例如:
<?xml version="1.0" encoding="GB2312"?>
<project name="weblogic ant task" default="build">
<target name="detect.file" >
<condition property="fileIsExists" >
<and>
<available file="c:/123.txt"/>
</and>
</condition>
</target>
<target name="echoDemo" if="fileIsExists" depends="detect.file">
<echo message="hello ant"/>
</target>
<target name="build">
<antcall target="echoDemo"/>
</target>
</project>
上面判断一个文件,如果存在的话 fileIsExists 就为true,echoDemo这个task在执行前会先判断fileIsExists 是否为true如果不为true就
不执行了。c盘下面有123.txt的话会打印hello ant 否则不会打印。
这里面还有一个小陷阱,我习惯使用antcall,不喜欢使用depends,但是使用antcall的话就会有问题,例如我最开始这么写的,就不行。
<?xml version="1.0" encoding="GB2312"?>
<project name="weblogic ant task" default="build">
<target name="detect.file">
<condition property="fileIsExists">
<and>
<available file="c:/123.txt"/>
</and>
</condition>
</target>
<target name="echoDemo" if="fileIsExists">
<echo message="hello ant"/>
</target>
<target name="build">
<antcall target="detect.file"/>
<antcall target="echoDemo"/>
</target>
</project>
使用antcall的话在echoDemo这个task执行的时候fileIsExists这个属性永远不为true,即便在执行完detect.file后它已经为true了。
ant中处理逻辑判断
最新推荐文章于 2015-10-30 11:44:27 发布