尽管我已经通过taskdef添加了ant-contrib,但Apache ant并不识别'for'任务/宏

Him*_*dav 15 ant build

我在做ant构建时得到了以下内容:

Build\build.xml:247: Problem: failed to create task or type
for
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)

build.xml第247行是 <for param="file">

已经定义<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>,它没有用.然后我特意添加了以下但它仍然无法正常工作.

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${env.ANT_HOME}/lib/ant-contrib-1.0b3.jar"/>
        </classpath>
    </taskdef>
Run Code Online (Sandbox Code Playgroud)

我在C:\ Softwares\apache-ant-1.8.4\lib目录下有ant-contrib-1.0b3.jar.这里缺少什么?

Dav*_* W. 34

如果您将AntContrib jar放在$ANT_HOME/ lib目录中,那么您真正需要做的就是:

<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
Run Code Online (Sandbox Code Playgroud)

实际上要使用该<for/>任务,您需要这样做:

<taskdef resource="net/sf/antcontrib/antlib.xml"/>
Run Code Online (Sandbox Code Playgroud)

注意你必须使用antlib.xml而不是antcontrib.properties.请仔细阅读安装说明.这很容易错过.

如果您在组项目中执行此操作,我建议您将ant-contrib.jar放入项目中.然后将它们添加到版本控制系统中的项目中.这样,其他开发人员可以使用ant-contrib任务构建您的构建,而无需下载ant-contrib jar并将其安装在$ ANT_HOME目录中.

假设您创建了一个名为的目录ant-contrib.dir并将其放在项目的根目录中,然后将ant-contrib jar放在该文件夹中.把它放在你的项目中:

<taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
          <fileset dir="${basedir}/ant-contrib.dir"/>
    </classpath>
</taskdef>
Run Code Online (Sandbox Code Playgroud)