Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用ant中的condition元素设置另一个属性?_Java_Ant - Fatal编程技术网

Java 如何使用ant中的condition元素设置另一个属性?

Java 如何使用ant中的condition元素设置另一个属性?,java,ant,Java,Ant,我有一个build.xml与ant一起使用,我试图在目标中设置一个条件: 首先,我在这里设置了可以正常工作的属性: <condition property="isWindows"> <os family="windows"/> </condition> 然后我尝试在目标中使用它: <target name="-post-jar"> <condition property="isWindows" value="true"&

我有一个build.xml与ant一起使用,我试图在目标中设置一个条件:

首先,我在这里设置了可以正常工作的属性:

<condition property="isWindows">
    <os family="windows"/>
</condition>

然后我尝试在目标中使用它:

<target name="-post-jar">
    <condition property="isWindows" value="true">
         <!-- set this property, only if isWindows set -->
         <property name="launch4j.dir" location="launch4j" />
    </condition>

    <!-- Continue doing things, regardless of property -->
    <move file="${dist.jar.dir}" tofile="myFile"/>
    <!-- etc -->
</target>

我得到一个错误:“条件不支持嵌套的“property”元素。”
问题是:如何在目标中正确放置条件,以及为什么错误引用“嵌套”属性?

条件用于定义属性,而不是基于属性值执行某些操作

使用可根据属性值执行某些任务。

的条件嵌套在
条件
元素中

使用
属性
属性指定要设置的属性,并使用
条件
元素上的
属性指定满足条件时的值。此外,您可以为属性设置一个值,该属性的条件不符合
else
属性

要检查属性是否设置为
条件的条件,请使用



这与ant文档中的语法完全相同。你确定你没有在条件任务中创建元素(你在这里写了“do things in here”)?。啊……我在那里创建了另一个属性(下一行是no no?我最初有target+if,但目标名称是固定的(-post jar)因此,我无法复制它,因此尝试在目标本身中设置一些条件。谢谢JB。只需使您的-post-jar目标依赖于另一个具有if属性的目标。谢谢JB Nizet。通过重新安排任务、向新目标添加an,然后设置if=“isWindows”来解决此问题在这个新目标上。我相信嵌套错误指的是将标签放在
<condition property="isWindows">
    <os family="windows"/>
</condition>   

<target name="-post-jar">
    <!--Only set property if isWindows -->
    <condition property="launch4j.dir" value="launch4j">
         <isset property="isWindows"/>
    </condition>

    <!-- Continue doing things, regardless of property -->
    <move file="${dist.jar.dir}" tofile="myFile"/>
    <!-- etc -->
</target>