ant-contrib - if/then/else 任务 [英] ant-contrib - if/then/else task

查看:29
本文介绍了ant-contrib - if/then/else 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using ant, and I have a problem with if/then/else task, (ant-contrib-1.0b3.jar). I am running something that can be simplified with build.xml below.

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

I am expecting to obtain from 'ant -Dgiv=Luke' the message

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

但似乎在 if/then/else 中没有覆盖属性giv"..

but it seems property "giv" is not overwritten inside if/then/else..

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

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

Is it depending from the fact I am using equals task with ${giv} ? Otherwise what is wrong in my code?

build.xml 代码:

build.xml CODE:

<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 Contrib JAR 中定义.

Ant Properties are very hard to overwrite (if not impossible). What you need is a Variable. These are also defined in the Ant Contrib JAR.

编辑您的示例:

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

这篇关于ant-contrib - if/then/else 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆