【问题标题】:Java, using Ant with Apache Ivy problemsJava,使用 Ant 和 Apache Ivy 问题
【发布时间】:2011-11-08 12:23:04
【问题描述】:

我使用 ANT 将我的东西部署到 Tomcat。但是我遇到了缺少依赖项的问题,我想添加 Ivy,因为它已被推荐。

现在我将它添加到我的 build.xml 文件中:

<!-- Ivy settings start-->

    <condition property="ivy.home" value="${env.IVY_HOME}">
        <isset property="env.IVY_HOME" />
    </condition>


    <target name="download-ivy" unless="offline">
        <mkdir dir="${ivy.jar.dir}"/>
            <!-- download Ivy from web site so that it can be used even without any special installation -->
        <get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" 
            dest="${ivy.jar.file}" usetimestamp="true"/>
    </target>


    <target name="init-ivy" depends="download-ivy">
        <!-- try to load ivy here from ivy home, in case the user has not already dropped
        it into ant's lib dir (note that the latter copy will always take precedence).
        We will not fail as long as local lib dir exists (it may be empty) and
        ivy is in at least one of ant's lib dir or the local lib dir. -->
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
        uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>

    <target name="go" depends="init-ivy" description="--> resolve dependencies, compile and run the project">
    <echo message="using ivy to resolve commons-lang 2.1..."/>
    <!--
    here comes the magic line: asks ivy to resolve a dependency on commons-lang 2.1 and to build an ant path with it from its cache
    -->
    <ivy:cachepath organisation="commons-lang" module="commons-lang" revision="2.1" pathid="lib.path.id" inline="true"/>
    </target>
<!-- Ivy settings end-->

我正在尝试将 common-lang JAR 文件添加到我的项目中。 这是我得到的输出:

    Buildfile: C:\Users\Jansu\workspace\HelloWorld\build.xml
build:
deploywar:
download-ivy:
      [get] Getting: http://repo2.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar
      [get] To: C:\Users\Jansu\.ant\lib\ivy-2.2.0.jar
      [get] Not modified - so not downloaded
init-ivy:
go:
     [echo] using ivy to resolve commons-lang 2.1...
[ivy:cachepath] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
[ivy:cachepath] :: loading settings :: url = jar:file:/C:/Users/Jansu/.ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:cachepath] :: resolving dependencies :: commons-lang#commons-lang-caller;working
[ivy:cachepath]     confs: [default, master, compile, provided, runtime, system, sources, javadoc, optional]
[ivy:cachepath]     found commons-lang#commons-lang;2.1 in public
[ivy:cachepath] :: resolution report :: resolve 151ms :: artifacts dl 10ms
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |   1   |   0   |   0   |   0   ||   1   |   0   |
    |      master      |   1   |   0   |   0   |   0   ||   1   |   0   |
    |      compile     |   1   |   0   |   0   |   0   ||   0   |   0   |
    |     provided     |   1   |   0   |   0   |   0   ||   0   |   0   |
    |      runtime     |   1   |   0   |   0   |   0   ||   0   |   0   |
    |      system      |   1   |   0   |   0   |   0   ||   0   |   0   |
    |      sources     |   1   |   0   |   0   |   0   ||   1   |   0   |
    |      javadoc     |   1   |   0   |   0   |   0   ||   1   |   0   |
    |     optional     |   1   |   0   |   0   |   0   ||   0   |   0   |
    ---------------------------------------------------------------------
BUILD SUCCESSFUL
Total time: 2 seconds

我猜它有效.. 现在有 2 个问题:

1) 这些 JAR 文件出现在我的项目中的什么位置?

2) 如何添加其他 JAR 文件,例如 Spring 框架文件?

【问题讨论】:

  • Maven 2/3 更容易处理...

标签: java ant ivy


【解决方案1】:

这个:

<ivy:cachepath organisation="commons-lang" module="commons-lang" revision="2.1" pathid="lib.path.id" inline="true"/>
</target>

被称为inline retrieval 并告诉Ivy 从常春藤缓存中使用pathid="lib.path.id" 构建一个ant-path,jar 不会被复制到您的项目中。缓存在 $ {user.home}/.ivy2 中。

如果您想将工件下载到您的项目,您必须使用retrieve 任务并为您的项目定义一个ivy.xml。

【讨论】:

  • 我将在哪个 xml 文件中声明我需要 Ivy 下载的依赖项?
  • ivy.xml - 也许常春藤教程/快速入门会有所帮助:ant.apache.org/ivy/history/latest-milestone/tutorial/start.html
  • 谢谢 .. 现在它正在寻找某种解析器commons-lang#commons-lang;2.0: no resolver found for commons-lang#commons-lang: check your configuration@oers
  • 嗯,真的不知道。也许 2.0 不在存储库中?在您的问题中,您尝试了 2.1 版,该版本有效。
  • 嗯,我不确定,但这是我的新问题:stackoverflow.com/questions/7283757/…
猜你喜欢
  • 2018-03-25
  • 2011-11-13
  • 2012-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-14
  • 2011-06-24
  • 2011-10-05
相关资源
最近更新 更多