在本教程中,你可以不用特别的设置,非常简单的使用Ivy,Ivy使用maven2 repository 来实现你定义在Ivy文件中的以来,现在看下Ivy文件内容。
你可以从Ivy的 src/example/hello-ivy 找到Ivy.xml
<ivy-module version="2.0">The format of this file should pretty easy to understand, but let's give some details about what is declared here. First, the root element ivy-module, with the version attribute used to tell Ivy which version of Ivy this file uses.
<info organisation="org.apache" module="hello-ivy"/>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.0"/>
<dependency org="commons-cli" name="commons-cli" rev="1.0"/>
</dependencies>
</ivy-module>
内容很简单, 不多解释了
ivy-module 表示ivy版本
info
<dependency>To convert this into an Ivy dependency declaration, all you have to do is use the groupId as organization, the artifactId as module name, and the version as revision. That's what we did for the dependencies in this tutorial, that is commons-lang and commons-cli. Note that having commons-lang and commons-cli as organization is not the best example of what the organization should be. It would be better to use org.apache, org.apache.commons or org.apache.commons.lang. However, this is how these modules are identified in the maven 2 repository, so the simplest way to get them is to use the details as is (you will see in Building a repository that you can use namespaces to redefine these names if you want something cleaner).
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.0</version>
</dependency>
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="hello-ivy" default="run">As you can see, it's very easy to call Ivy to resolve and retrieve dependencies: all you need if Ivy is properly installed is to define an XML namespace in your Ant file (xmlns:ivy="antlib:org.apache.ivy.ant"). Then all the Ivy ant tasks will be available in this namespace.
...
<!-- =================================
target: resolve
================================= -->
<target name="resolve" description="--> retrieve dependencies with ivy">
<ivy:retrieve />
</target>
</project>
[ivy@apache:/ivy/hello-ivy]$ ant Buildfile: /ivy/hello-ivy/build.xml resolve: [ivy:retrieve] :: Apache Ivy 2.4.0-rc1 - 20140315220245 :: http://ant.apache.org/ivy/ :: [ivy:retrieve] :: loading settings :: url = jar:file:///home/ivy/ivy.jar!/org/apache/ivy/core/settings/ivysettings.xml [ivy:retrieve] :: resolving dependencies :: org.apache#hello-ivy;working@apache [ivy:retrieve] confs: [default] [ivy:retrieve] found commons-lang#commons-lang;2.0 in public [ivy:retrieve] found commons-cli#commons-cli;1.0 in public [ivy:retrieve] found commons-logging#commons-logging;1.0 in public [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.0/commons-lang-2.0.jar ... [ivy:retrieve] ................. (165kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-lang#commons-lang;2.0!commons-lang.jar (739ms) [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.0/commons-lang-2.0-javadoc.jar ... [ivy:retrieve] .......................................... (467kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-lang#commons-lang;2.0!commons-lang.jar(javadoc) (1391ms) [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-lang/commons-lang/2.0/commons-lang-2.0-sources.jar ... [ivy:retrieve] ................... (245kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-lang#commons-lang;2.0!commons-lang.jar(source) (889ms) [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-cli/commons-cli/1.0/commons-cli-1.0-javadoc.jar ... [ivy:retrieve] .............. (92kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-cli#commons-cli;1.0!commons-cli.jar(javadoc) (574ms) [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-cli/commons-cli/1.0/commons-cli-1.0-sources.jar ... [ivy:retrieve] .............. (48kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-cli#commons-cli;1.0!commons-cli.jar(source) (456ms) [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-cli/commons-cli/1.0/commons-cli-1.0.jar ... [ivy:retrieve] ........ (29kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-cli#commons-cli;1.0!commons-cli.jar (413ms) [ivy:retrieve] downloading http://repo1.maven.org/maven2/commons-logging/commons-logging/1.0/commons-logging-1.0.jar ... [ivy:retrieve] ...... (21kB) [ivy:retrieve] .. (0kB) [ivy:retrieve] [SUCCESSFUL ] commons-logging#commons-logging;1.0!commons-logging.jar (415ms) [ivy:retrieve] :: resolution report :: resolve 3686ms :: artifacts dl 4921ms [ivy:retrieve] :: evicted modules: [ivy:retrieve] commons-lang#commons-lang;1.0 by [commons-lang#commons-lang;2.0] in [default] --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | default | 4 | 3 | 3 | 1 || 7 | 7 | --------------------------------------------------------------------- [ivy:retrieve] :: retrieving :: org.apache#hello-ivy [ivy:retrieve] confs: [default] [ivy:retrieve] 7 artifacts copied, 0 already retrieved (1069kB/68ms) run: [mkdir] Created dir: /ivy/hello-ivy/build [javac] Compiling 1 source file to /ivy/hello-ivy/build [java] standard message : hello ivy ! [java] capitalized by org.apache.commons.lang.WordUtils : Hello Ivy ! BUILD SUCCESSFUL Total time: 10 seconds
[ivy@apache:/ivy/hello-ivy]$ ant Buildfile: /ivy/hello-ivy/build.xml resolve: [ivy:retrieve] :: Apache Ivy 2.4.0-rc1 - 20140315220245 :: http://ant.apache.org/ivy/ :: [ivy:retrieve] :: loading settings :: url = jar:file:///home/ivy/ivy.jar!/org/apache/ivy/core/settings/ivysettings.xml [ivy:retrieve] :: resolving dependencies :: org.apache#hello-ivy;working@apache [ivy:retrieve] confs: [default] [ivy:retrieve] found commons-lang#commons-lang;2.0 in public [ivy:retrieve] found commons-cli#commons-cli;1.0 in public [ivy:retrieve] found commons-logging#commons-logging;1.0 in public [ivy:retrieve] :: resolution report :: resolve 139ms :: artifacts dl 13ms [ivy:retrieve] :: evicted modules: [ivy:retrieve] commons-lang#commons-lang;1.0 by [commons-lang#commons-lang;2.0] in [default] --------------------------------------------------------------------- | | modules || artifacts | | conf | number| search|dwnlded|evicted|| number|dwnlded| --------------------------------------------------------------------- | default | 4 | 0 | 0 | 1 || 7 | 0 | --------------------------------------------------------------------- [ivy:retrieve] :: retrieving :: org.apache#hello-ivy [ivy:retrieve] confs: [default] [ivy:retrieve] 0 artifacts copied, 7 already retrieved (0kB/7ms) run: [java] standard message : hello ivy ! [java] capitalized by org.apache.commons.lang.WordUtils : Hello Ivy ! BUILD SUCCESSFUL Total time: 1 second