簡體   English   中英

Java,將Ant與Apache Ivy問題結合使用

[英]Java, using Ant with Apache Ivy problems

我正在使用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-->

為此,我試圖將通用語言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

我猜它有效..現在有兩個問題:

1) 這些JAR文件在我的項目中出現在哪里?

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

這個:

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

這稱為內聯檢索,並告訴Ivy從常春藤緩存中使用pathid="lib.path.id"構建一個ant-path,jar將不會復制到您的項目中。 緩存位於$ {user.home} /。ivy2中。

如果要將工件下載到項目中,則必須使用retrieve任務並為項目定義ivy.xml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM