本文介绍了ANT:使用条件标签,<IF>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做这样的事情

<target name="clean" description="clean">
    <if>
        <available file="${build}" type="dir" />
        <then>
            <delete dir="${build}" />
        </then>
    </if>
</target>

根据 suggestions 在 stackoverflow.com 上找到,我下载了 ant-contrib-1.0b3.jar 并将其放入我的路径中

As per suggestions found on stackoverflow.com, i downloaded ant-contrib-1.0b3.jar and put it into my path

此外,在 Ant Build 配置下,在类路径中,我有

Additionally, under Ant Build configuration, in classpath, i have

运行我的 ANT 脚本时,我仍然得到

When running my ANT script, i still get

BUILD FAILED
C:\Repositories\blah\build.xml:60: 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.

我错过了什么?请指教

推荐答案

或者,一旦可以在您的 ANT 脚本中包含以下行

Alternately, once can include the following line in your ANT script

<taskdef resource="net/sf/antcontrib/antlib.xml" />

只要 ant-contribs 在你的路径中,其他什么都不需要

As long as ant-contribs is in your path, nothing else is needed

这个解决方案更简洁一些,因为可以访问所有标签,而不仅仅是手动指定的标签

This solution is a bit cleaner, as one gains access to ALL the tags, not just the ones manually specified

这篇关于ANT:使用条件标签,&lt;IF&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:11