Ant教程

Ant If-Unless

Ant IfUnless都是 <target> 元素(任务)的属性。这些属性用于控制任务是否运行。
除了target之外,还可以与 <target> <junit> 元素。
在早期版本和Ant 1.7.1 中,这些属性只是属性名称。如果定义了属性,则即使值是false也可以运行。
例如,即使传递false后也无法停止执行。
//build.xml
<project name="java-ant project" default="run">
<target name="compile">
    <available property="file.exists" file="some-file"/>
    <echo>File is compiled</echo>
</target>
<target name="run" depends="compile" if="file.exists">
    <echo>File is executed</echo>
</target>
</project>
输出:
无参数: 运行时不带命令行参数。只需在终端输入 ant ,但首先定位到项目位置,它将显示空输出。
带有参数: 现在传递参数,但 false
Ant -0Dfile.exists = false

Apache Ant if-unless
现在传递参数,但 true
Ant -Dfile.exists = true

Apache Ant if-unless
从Ant 1.8.0开始,我们可以使用允许仅在value为真正。在新版本中,它为我们提供了更大的灵活性,现在我们可以在命令行中覆盖。参见下面的示例。
//build.xml
<project name="java-ant project" default="run">
<target name="compile" unless="file.exists">
    <available property="file.exists" file="some-file"/>
</target>
<target name="run" depends="compile" if="${file.exists}">
    <echo>File is executed</echo>
</target>
</project>
输出:
无参数: 在不使用命令行参数的情况下运行它。只需在终端输入 ant ,但首先定位到项目的位置,它将显示空的输出。
带参数: 现在传递参数,但 false
Ant -Dfile.exists = false
无输出,因为这次如果没有执行。
带有参数: 现在传递参数,但 true 。现在它显示输出,因为评估了if。
Ant -Dfile.exists = true

Apache Ant if-unless
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4