gpt4 book ai didi

ant-contrib - if/then/else 任务

转载 作者:行者123 更新时间:2023-12-03 22:48:05 25 4
gpt4 key购买 nike

我正在使用 ant,并且在 if/then/else 任务(ant-contrib-1.0b3.jar)上遇到问题。
我正在运行一些可以使用下面的 build.xml 进行简化的东西。

我期待从 'ant -Dgiv=Luke' 获得消息

input name: Luke
should be overwritten with John except for Mark: John

但似乎属性“giv”在if/then/else中没有被覆盖..
input name: Luke
should be overwritten with John except for Mark: Luke

是否取决于我正在使用 equals 任务与 ${giv} 的事实? ?
否则我的代码有什么问题?

build.xml 代码:
<project name="Friend" default="ifthen" basedir=".">

<property name="runningLocation" location="" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${runningLocation}/antlib/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>

<target name="ifthen">
<echo message="input name: ${giv}" />
<if>
<equals arg1="${giv}" arg2="Mark" />
<then>
</then>
<else>
<property name="giv" value="John" />
</else>
</if>
<echo message="should be overwritten with John except for Mark: ${giv}" />
</target>
</project>

最佳答案

在 Ant 中,属性总是设置一次,之后该变量不再可更改。

下面是一个使用标准 Ant(没有 ant-contrib)的解决方案,这对于不想要额外依赖的人来说可能很有用。

<target name="test"  >
<echo message="input name: ${param}" />

<condition property="cond" >
<equals arg1="${param}" arg2="Mark" />
</condition>
</target>

<target name="init" depends="test" if="cond">
<property name="param2" value="Mark" />
</target>

<target name="finalize" depends="init">
<property name="param2" value="John" />
<echo message="should be overwritten with John except for Mark: ${param2}" />
</target>

关于ant-contrib - if/then/else 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5116619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com