如果在apache中的isset蚂蚁失败了

Tha*_*Pap 3 apache ant ant-contrib

我试图通过以下方式检查ant中是否存在属性:

<target name="test">
    <property name="testproperty" value="1234567890"/>
    <if>
        <isset property="testproperty"/>
        <then>
            <echo message="testproperty exists"/>
        </then>
        <else>
            <echo message="testproperty does not exist"/>
        </else>
    </if>
</target>
Run Code Online (Sandbox Code Playgroud)

结果是消息失败:

build.xml:536: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Run Code Online (Sandbox Code Playgroud)

我必须对isset做错了,因为以下顺利运行:

<target name="test">
    <property name="testproperty" value="1234567890"/>
    <echo message="'${testproperty}'"/>
</target>
Run Code Online (Sandbox Code Playgroud)

请指教 :)

Mar*_*nor 9

if任务不是标准的ANT任务.这是目标的条件执行的工作方式

<project name="demo" default="test">

  <target name="property-exists" if="testproperty">
    <echo message="testproperty exists"/>
  </target>

  <target name="property-no-exists" unless="testproperty">
    <echo message="testproperty does not exist"/>
  </target>

  <target name="test" depends="property-exists,property-no-exists">
  </target>

</project>
Run Code Online (Sandbox Code Playgroud)

  • 这个++,ant-contrib将导致眼泪. (2认同)

Tha*_*Pap 7

显然我错过了ant-contrib jar文件,可以在这里找到:http:
//ant-contrib.sourceforge.net/