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

IAm*_*aja 25 java ant ivy

可能重复:
常春藤无法解决依赖性,无法找到原因

我正在尝试运行以下构建任务(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>
Run Code Online (Sandbox Code Playgroud)

当我运行时,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
Run Code Online (Sandbox Code Playgroud)

当我转到$ {ANT_HOME}/lib时,我没有看到任何标记为"antlib*.jar"的JAR.

所以我我下载了一个不包含Antlib的Ant版本,现在我正在使用Ivy(使用Antlib),构建是否会窒息?

如果这是一个问题的antlib,那么我相信,我想提供的发行版之一在这里.如果是这样,有人可以确认我应该使用哪一个(只包含Antlib而不是其他任何东西),并确认安装它的过程; 即,它是否就像在$ {ANT_HOME}/lib中放入正确的JAR一样简单?等等.

如果这是一个常春藤问题,那么有人可以指出我正确的方向可能会发生什么?

如果这既不是Antlib也不是常春藤,对于上面的问题同样如此.提前致谢!

Shw*_*nka 61

我想你可能会遗漏Apache IVY库.从这里下载 - apache ivy在你的ant lib目录中复制jar.

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

  1. 下载并安装Ant(例如C:\Apps\Tools\apache-ant-1.9.7).
  2. 下载并提取常春藤(例如C:\Users\UserName\Downloads\apache-ivy-2.4.0)
  3. 复制C:\Users\UserName\Downloads\apache-ivy-2.4.0\ivy-2.4.0.jarC:\Apps\Tools\apache-ant-1.9.7\lib.

Ant配置为使用Ivy.

  • 更方便的方法是使用[Ivy Eclipse更新站点](http://www.apache.org/dist/ant/ivyde/updatesite) - 安装"Apache Ivy"-Libs(Apache Ivy和Apache Ivy Ant Taks) ) (5认同)
  • @ 4herpsand7derpsago [antlib](https://ant.apache.org/manual/Types/antlib.html)是ant中的通用术语,而不是单独的工具.如果你得到"无法从资源org/apache/ivy/ant/antlib.xml加载定义.找不到它",那么它意味着类路径中没有jar文件,其中包含和"org/apache/ivy/ant/antlib.xml".因为这个文件是ivy.xml的一部分,你知道lib缺失了. (3认同)
  • “你的 ant lib 目录”是“ANT_HOME/lib 和一个用户特定的目录,${user.home}/.ant/lib。”如果你不熟悉 ant(就像我一样) (2认同)