---
title: "ivy中文参考文档(12)-单独使用"
author: "skydream"
date: "2009-07-23T13:36:00Z"
tags: []
categories: ["编程语言"]
slug: "ivy-12"
draft: false
lastmod: "2009-09-02T16:36:40Z"
id: 437908
url: "https://skydream.iteye.com/blog/437908"
---

1\) 单独使用

    ivy可以非常容易的作为一个单独的程序使用。你所需要的只是一个java1.4+的运行环境(JRE)!

    这是如何调用它的例子：

java  - jar ivy.jar  -?

    它将实现类似这样的在线帮助：

==== settings options  
 -settings  &lt; settingsfile &gt;      use given file for settings  
 -cache  &lt; cachedir &gt;             use given directory for cache  
 -novalidate                  do not validate ivy files against xsd  
 -m2compatible                use maven2 compatibility

==== resolve options  
 -ivy  &lt; ivyfile &gt;                use given file as ivy file  
 -dependency  &lt; organisation &gt;   &lt; module &gt;   &lt; revision &gt;  
                              use this instead of ivy file to do the rest of the  
                               work with this as a dependency.  
 -confs  &lt; configurations &gt;       resolve given configurations

==== retrieve options  
 -retrieve  &lt; retrievepattern &gt;   use given pattern as retrieve pattern  
 -sync                        use sync mode for retrieve

==== cache path options  
 -cachepath  &lt; cachepathfile &gt;    outputs a classpath consisting of all dependencies  
                               in cache (including transitive ones) of the given  
                               ivy file to the given cachepathfile

==== deliver options  
 -deliverto  &lt; ivypattern &gt;       use given pattern as resolved ivy file pattern

==== publish options  
 -publish  &lt; resolvername &gt;       use given resolver to publish to  
 -publishpattern  &lt; artpattern &gt;  use given pattern to find artifacts to publish  
 -revision  &lt; revision &gt;          use given revision to publish the module  
 -status  &lt; status &gt;              use given status to publish the module

==== http auth options  
 -realm  &lt; realm &gt;                use given realm for HTTP AUTH  
 -host  &lt; host &gt;                  use given host for HTTP AUTH  
 -username  &lt; username &gt;          use given username for HTTP AUTH  
 -passwd  &lt; passwd &gt;              use given password for HTTP AUTH

==== launcher options  
 -main  &lt; main &gt;                  the FQCN of the main class to launch  
 -args  &lt; args &gt;                  the arguments to give to the launched process  
 -cp  &lt; cp &gt;                      extra classpath to use when launching process

==== message options  
 -debug                       set message level to debug  
 -verbose                     set message level to verbose  
 -warn                        set message level to warn  
 -error                       set message level to error

==== help options  
 -?                           display this help  
 -deprecated                  show deprecated options

    从1.3版本后系统属性被包含在ivy变量中，因此你可以很容易的定义ivy变量，类似这样：

    2) 例子

    java  - jar ivy.jar

     用默认配置和当前目录里面的ivy.xml调用ivy

java  - jar ivy.jar  - settings path / to / myivysettings.xml  - ivy path / to / myivy.xml

    用给定的ivysettings文件和给定的ivy文件调用ivy

    1. 从1.3版本开始

java  - jar ivy.jar  - settings path / to / myivysettings.xml  - dependency apache commons - lang  2.0

    用给定的ivysettings文件调用ivy并解析依赖apache commons-lang 2.0.

    这等同于:

java -jar ivy.jar -settings path/to/myivysettings.xml -ivy ivy.xml

     
    而ivy.xml内容如下:

&lt; ivy-module  version ="1.0" &gt;  
   &lt; info  organisation ="org"  
       module ="standalone"  
       revision ="working"  
    /&gt;  
   &lt; dependencies &gt;  
     &lt; dependency  org ="apache"  name ="commons-lang"  rev ="2.0"  conf ="default-&gt;\*" /&gt;  
   &lt;/ dependencies &gt;  
&lt;/ ivy-module &gt;

    2. 从1.3版本开始

java  - jar ivy.jar  - settings path / to / myivysettings.xml  - ivy path / to / myivy.xml  - cachepath mycachefile.txt

    用给定的ivysettings文件调用ivy并解析在给定的ivy文件中发现的依赖，然后输出被解析的在缓存中的制品的classpath到文件中。这个文件随后可以被用来为任何java程序定义符合所有被解析的依赖的classpath。

    3. 从 1.4开始

java  - jar ivy.jar  - settings path / to / myivysettings.xml  - dependency bar foo  2.0   - main org.bar.foo.FooMain

用给定的ivysettings文件调用ivy并解析依赖bar foo 2.0,然后用解析出来的制品运行类org.foo.FooMain。