<?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了,但是它不会被传递到下一个task,没用深入研究过ant,所以具体内部实现还不了解。
下面是ant的官方参考文档
更复杂的可以参考
http://ant.apache.org/manual/CoreTasks/conditions.html
Ant构建文件默认命名为build.xml,也可以取其他的名字。只不过在运行的时候把这个命名当作参数传给Ant。构建文件可以放在任何的位置。一般做法是放在项目顶层目录中,这样可以保持项目的简洁和清晰。下面是一个典型的项目层次结构。(1) src存放文件。
(2) class存放编译后的文件。
(3) lib存放第三方JAR包。
(4) dist存放打包,发布以后的代码。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)