Ant目标失败:是Antlib还是Ivy问题?

27

可能重复:
Ivy fails to resolve a dependancy, unable to find cause

我正在尝试运行以下构建任务(initIvy):

<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject-build" default="package" basedir=".." xmlns:ivy="antlib:org.apache.ivy.ant">
    <property file="build/build.properties"/>
    <property environment="env"/>

    <!-- Ant library path, including all of its plugins. -->
    <path id="ant.lib.path">
        <fileset dir="${env.ANT_HOME}/lib" includes="*.jar"/>
    </path>

    <!-- CONFIGURE IVY -->
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
            uri="antlib:org.apache.ivy.ant" classpathref="ant.lib.path"/>

    <!-- Use Ivy tasks to resolve dependencies into the local Ivy cache. -->
    <target name="initIvy">
        <!-- Initialize Ivy and connect to host repository. -->
        <echo message="Initializing Apache Ivy and connecting to the host repository."/>
        <ivy:settings url="${ivy.std.repo.settings.url}" realm="${ivy.std.repo.realm}" username="${ivy.std.repo.username}" passwd="${ivy.std.repo.password}"/>

        <!-- Clear/flush the Ivy cache. -->
        <echo message="Cleaning the local Ivy cache for the current build."/>
        <ivy:cleancache/>
    </target>

    <!-- Rest of buildfile omitted for brevity. -->

</project>

我运行ant -buildfile build.xml initIvy时,会得到以下输出:

Buildfile: /<path-to-my-project>/build/build.xml
    [taskdef] Could not load definitions from resource org/apache/ivy/ant/antlib.xml. It could not be found.

initIvy:
    [echo] Initializing Apache Ivy and connecting to the host repository.

BUILD FAILED
/<path-to-my-project>/build/build.xml:81: 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:
    -/<path-to-my-ANT_HOME>/lib
    -/home/myUser/.ant/lib
    -a directory added on the command line with the -lib argument
当我进入 ${ANT_HOME}/lib 目录时,我没有看到任何标记为 "antlib*.jar" 的 JAR 文件。
因此,我猜测我下载的 Ant 版本不包括 Antlib,现在我正在使用 Ivy(它使用 Antlib),构建过程出现问题?
如果这是一个 Antlib 问题,那么我认为我需要使用这里提供的其中一个发行版。如果是这样,请有人确认我应该使用哪个(仅包含 Antlib 而不包含其他内容),并确认安装过程;例如,是否只需将正确的 JAR 放置在 ${ANT_HOME}/lib 中?等等。
如果这是一个 Ivy 问题,那么有人能否指导我正确的方向呢?
如果这既不是 Antlib 也不是 Ivy,那么直接回答上面的问题即可。提前感谢!
1个回答

68

我觉得你可能没有安装Apache IVY库。你可以从这里下载 - apache ivy,将jar文件复制到你的Ant lib目录中。

例如(根据需要更改版本号):

  1. 下载并安装Ant(例如,C:\Apps\Tools\apache-ant-1.9.7)。
  2. 下载并提取Ivy(例如,C:\Users\UserName\Downloads\apache-ivy-2.4.0)。
  3. C:\Users\UserName\Downloads\apache-ivy-2.4.0\ivy-2.4.0.jar 复制到C:\Apps\Tools\apache-ant-1.9.7\lib

Ant已配置为使用Ivy。


1
当时就是这样。我只是复制了Ivy lib JAR,忘记复制Ivy JAR。只是出于好奇,是什么给了你正确的想法?我只是想学习,这样下次我就可以自己诊断问题了!再次感谢! - IAmYourFaja
3
@4herpsand7derpsago antlib 是 Ant 中的一个通用术语,而不是一个单独的工具。如果您收到“Could not load definitions from resource org/apache/ivy/ant/antlib.xml. It could not be found." 错误消息,则意味着在类路径中没有包含 "org/apache/ivy/ant/antlib.xml" 的 jar 文件。因为这个文件是 ivy.xml 的一部分,所以可以推断缺失了库文件。 - oers
5
更方便的方法是使用Ivy Eclipse更新站点 - 安装“Apache Ivy”库(Apache Ivy和Apache Ivy Ant Taks)。 - teclis
2
你的 Ant lib 目录是 ANT_HOME/lib 和一个特定于用户的目录 ${user.home}/.ant/lib。如果你不熟悉 Ant(就像我一样),请参考相关资料。 - Yugang Zhou
1
我在Ubuntu 18中遇到了相同的问题--安装Ant $ sudo apt更新 $ sudo apt-get install ant--从以下网址下载Ivy http://ant.apache.org/ivy/download.cgi 我使用了Git方法 $ git clone https://git-wip-us.apache.org/repos/asf/ant-ivy.git $ ant jar您可以在以下位置找到ivy.jar --ant-ivy/build/artifact/jars做 $ cd /usr/share/ant/lib $ sudo ln -s path_to_ivy_jar然后,您就可以开始使用了。 - Ayush Chaurasia
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接