常春藤无法解决依赖,无法找到原因

Sim*_*han 32 eclipse ant ivy

使用时ivy:retrieve,它无法解决应下载的依赖项.输出如下所示:

Buildfile: C:\Users\Simon\workspace\apollo\build.xml
init:
resolve:

BUILD FAILED
C:\Users\Simon\workspace\apollo\build.xml:42: Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve
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:
        -C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
        -C:\Users\Simon\.ant\lib
        -a directory added on the command line with the -lib argument


Total time: 348 milliseconds
Run Code Online (Sandbox Code Playgroud)

build.xml看起来像这样的相关部分:

  <target name="resolve" depends="init">
    <ivy:retrieve pattern="${lib}/[artifact]-[revision].[ext]" sync="true" />
  </target>
Run Code Online (Sandbox Code Playgroud)

这里还列出了应该下载的内容(来自build.xml)

  <target name="doc" depends="build">
    <javadoc sourcepath="${src}" classpathref="libraries" access="private" destdir="${doc}" windowtitle="Apollo">
      <doclet name="org.jboss.apiviz.APIviz" pathref="libraries">
        <param name="-sourceclasspath" value="${bin}" />
        <param name="-author" />
        <param name="-version" />
        <param name="-use" />
        <param name="-nopackagediagram" />
      </doclet>
      <doctitle><![CDATA[<h1>Apollo</h1>]]></doctitle>
      <link href="http://download.oracle.com/javase/6/docs/api/" />
      <link href="http://docs.jboss.org/netty/3.2/api/" />
      <link href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/" />
      <link href="http://www.junit.org/apidocs/" />
      <link href="http://commons.apache.org/compress/apidocs/" />
      <link href="http://jruby.org/apidocs/" />
    </javadoc>
  </target>
Run Code Online (Sandbox Code Playgroud)

Mar*_*nor 53

ANT找不到常春藤罐子.需要下载,解压缩,并将ivy-xyzjar放入以下位置之一:

  • $ ANT_HOME/lib目录
  • $ HOME /赵军阳张志利/ lib目录

启用常春藤

Ivy被打包为antlib,因此要启用它,您需要执行以下操作

1)在构建文件的顶部声明ivy名称空间

<project ..... xmlns:ivy="antlib:org.apache.ivy.ant">
Run Code Online (Sandbox Code Playgroud)

2)在其中一个ant库目录中包含常春藤jar

您的错误消息指示了antlibs的一些可能位置:

This appears to be an antlib declaration. 
Action: Check that the implementing library exists in one of:
        -C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
        -C:\Users\Simon\.ant\lib
        -a directory added on the command line with the -lib argument
Run Code Online (Sandbox Code Playgroud)

注意:

antlib的美妙之处在于您不需要执行taskdef(如果您想将常春藤罐放在非标准位置,则可选)

如何引导构建

即使常春藤是一个ANT子项目,但由于一些莫名其妙的原因,常春藤不与ANT打包....

我通常在构建文件中包含以下目标来设置新环境:

<target name="bootstrap" description="Used to install the ivy task jar">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>
Run Code Online (Sandbox Code Playgroud)

它从Maven Central下载常春藤罐.

由于随后可以使用常春藤下载所有其他ANT任务,因此很少有人会在构建文件的顶部反对这个小小的丑陋.

  • 是.令人费解的是,为什么ANT项目默认不发布常春藤罐. (3认同)
  • 运行引导程序后,您可能需要重新启动eclipse。 (2认同)

oer*_*ers 11

如果您不能将常春藤库放在ant的类路径中,您需要自己定义它:

<path id="ivy.lib.path">
    <fileset dir="path/to/dir/with/ivy/jar" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
         uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
Run Code Online (Sandbox Code Playgroud)

入门教程中缺少这一点,但在此处列出:http://ant.apache.org/ivy/history/2.2.0/ant.html


Sma*_*der 5

当您运行 Ant 任务时,请确保类路径中存在 ivy.jar。在 eclipse -> 运行方式 -> Ant Build -> 编辑配置 -> 类路径选项卡中。尽管 Eclipse 在 ANT Home 中有 ivy.jar,但由于某种原因它没有被调用。