尽管jar在〜/ .ant / lib中,但Ant未能找到Ivy jar

时间:2014-11-14 11:38:10

标签: ant ivy

我有以下build.xml仅用于演示问题:

<project
    xmlns:ivy="antlib:org.apache.ivy.ant"
    name="test" default="test-ivy">
     <target name="test-ivy">
        <ivy:settings />
     </target>
</project>

当使用Ant(1.7.1)调用它时,我得到:

$ ant
Buildfile: build.xml

test-ivy:

BUILD FAILED
/home/voops/test/build.xml:7: Problem: failed to create task or type antlib:org.apache.ivy.ant:settings
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.
No types or tasks have been defined in this namespace yet

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -/usr/share/ant/lib
        -/home/voops/.ant/lib
        -a directory added on the command line with the -lib argument


Total time: 0 seconds

然而,Ivy jar确实存在于我的~/.ant/lib目录中:

$ whoami
voops
$ls /home/voops/.ant/lib/ivy-2.3.0.jar
-rw-rw-r-- 1 voops voops 1222059 Nov 11 14:55 /home/voops/.ant/lib/ivy-2.3.0.jar

看来我必须通过添加以下元素手动指示Ivy jar的位置:

<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml"  classpath="${user.home}/.ant/lib/ivy-2.3.0.jar"/> 

...在我的build.xml文件中。添加此元素后,构建成功。

为什么Ant无法找到常春藤,即使常春藤罐位于默认的~/.ant/lib位置并且必须明确告知在所述位置寻找它?

更新:似乎只有Ant 1.7.1才需要上述元素。对于Ant 1.8.2或Ant 1.9.4,我不必添加它。

1 个答案:

答案 0 :(得分:2)

这是由于构建文件中的XML名称空间声明:

xmlns:ivy="antlib:org.apache.ivy.ant"

由于正在使用前缀ivy:,因此uri任务中需要taskdef属性以允许使用前缀调用任务:

typedef文档中显示了一个示例:

  

uri:这个定义应该存在的uri。自Ant 1.6

以来

修改

antlib表示如果antlib放在Ant的主目录中,默认情况下Ant可以加载正确的资源:

  

当Ant遇到具有此模式的名称空间URI的元素时,它将检查默认类路径中的包目录中是否存在名为antlib.xml的资源。