当前位置: 首页 > 面试题库 >

我该如何解决在Apache Ivy中将模块X的多个工件检索到同一文件中?

花飞扬
2023-03-14
问题内容

我正在使用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" description="Download Ivy">
        <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" description="Initialize 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="update" depends="init-ivy" description="Download project dependencies">
        <!-- edited for brevity -->

        <ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" />
        <!-- edited for brevity -->
    </target>


    <target name="clean-all" depends="clean" description="Purge ivy cache">
        <ivy:cleancache/>
    </target>

<!-- Ivy settings end-->

这是我的ivy.xml:

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.1"/>
    </dependencies>
</ivy-module>

这是我的日志:

Buildfile: C:\Users\Jansu\workspace\HelloWorld\build.xml
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:
update:
[ivy:retrieve] :: Ivy 2.2.0 - 20100923230623 :: http://ant.apache.org/ivy/ ::
[ivy:retrieve] :: loading settings :: url = jar:file:/C:/Users/Jansu/.ant/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:retrieve] :: resolving dependencies :: org.apache#hello-ivy;working@Jansu-PC
[ivy:retrieve]  confs: [default]
[ivy:retrieve]  found commons-lang#commons-lang;2.1 in public
[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.1/commons-lang-2.1.jar ...
[ivy:retrieve] ................................................................................................................................................................................................................................................................................................................................................................................................................. (202kB)
[ivy:retrieve] .. (0kB)
[ivy:retrieve]  [SUCCESSFUL ] commons-lang#commons-lang;2.1!commons-lang.jar (1704ms)
[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.1/commons-lang-2.1-sources.jar ...
[ivy:retrieve] ........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................ (255kB)
[ivy:retrieve] .. (0kB)
[ivy:retrieve]  [SUCCESSFUL ] commons-lang#commons-lang;2.1!commons-lang.jar(source) (1819ms)
[ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.1/commons-lang-2.1-javadoc.jar ...
[ivy:retrieve] .........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
[ivy:retrieve] ................................................................................................................................................................................................................................................................ (518kB)
[ivy:retrieve] .. (0kB)
[ivy:retrieve]  [SUCCESSFUL ] commons-lang#commons-lang;2.1!commons-lang.jar(javadoc) (2817ms)
[ivy:retrieve] :: resolution report :: resolve 2094ms :: artifacts dl 6357ms
    ---------------------------------------------------------------------
    |                  |            modules            ||   artifacts   |
    |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
    ---------------------------------------------------------------------
    |      default     |   1   |   1   |   1   |   0   ||   3   |   3   |
    ---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: org.apache#hello-ivy
[ivy:retrieve]  confs: [default]

这是错误:

BUILD FAILED
    C:\Users\Jansu\workspace\HelloWorld\build.xml:177: impossible to ivy retrieve: java.lang.RuntimeException: problem during retrieve of org.apache#hello-ivy: java.lang.RuntimeException: Multiple artifacts of the module commons-lang#commons-lang;2.1 are retrieved to the same file! Update the retrieve pattern  to fix this error.

    Total time: 11 seconds

看来错误来自这种模式?:

<ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" />

但这对我来说似乎很牢固。

有什么建议?


问题答案:

您必须扩展您的模式以包括类型,以便每个工件都可以拥有自己的本地文件:

<ivy:retrieve pattern="lib/[conf]/[artifact]-[type]-[revision].[ext]" />

或者,如果您不需要源代码和Javadoc,则可以将依赖项更改为:

<ivy-module version="2.0">
    <info organisation="org.apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.1" conf="default->master"/>
    </dependencies>
</ivy-module>

它将仅检索依赖项的master-conf(jar)。



 类似资料:
  • 在我的Android应用程序项目中,我试图避免在我的项目中引用一个外部Maven库,否则我会从那里加载多个。组成一个SDK的aar工件。 相反,我想将 .aar 文件放入我的项目中,然后从我的一个 Gradle Android 库模块中引用它们。 我已经尝试了不同的方法——但都不管用。 灵感来自 https://stackoverflow.com/a/72672032/35689 在这里,我的工件

  • 问题内容: 我有一个包含3个组件的项目,并且 在中,我有以下关注者 当我跑步时,我看到 每个模块都会生成一个jar文件。 问题 :如何将它们合并为一个? 我是Maven新手,不知道要寻找什么来完成此任务,请提供指针 问题答案: 那很简单。创建另一个名为或类似的模块: 模块应依赖于所有其他模块: 并包装: 您还需要输入。而已。

  • 我正在尝试将我的API文档分解成多个JSON文件,这些文件可以独立编辑。我能找到的所有示例都使用了Swagger1.2模式,它有一个“api”:{}对象来分解它。2.0模式(http://json.schemastore.org/swagger-2.0)中似乎缺少这一点。定义的只是一个“路径”数组,它将所有APIendpoint绑定到这个数组中。这在swagger-ui中的效果是,有一个单一的“默

  • 我想通过ivy将jar检索到特定的文件夹(如lib ),下面是我在build.xml中的检索定义: 还有我的常春藤的定义。xml如下: 但它总是抛出: 我读过一些类似的问题,以及他们建议将检索模式更改为更复杂的模式。我尝试了类似“[artifact]-revision.[ext]”的方法,但没有帮助。当我执行“ivy.resolve”时,效果很好。关于这个问题有什么建议吗?

  • 问题内容: 我想将五个文件的内容照原样复制到一个文件中。我尝试使用cp为每个文件执行此操作。但这会覆盖从先前文件复制的内容。我也试过 它没有用。 我希望我的脚本在每个文本文件的末尾添加换行符。 例如。文件1.txt,2.txt,3.txt。将1,2,3的内容放入0.txt 我该怎么做 ? 问题答案: 您需要(concatenate的简称)命令,并使用shell重定向()进入输出文件