Ivy与Ant集成

http://blog.csdn.net/lisonghua/archive/2009/11/05/4770260.aspx

 

 

 基本配置步骤如下: 

1、copy Ivy插件到ant_home/lib下; 

2、在项目根目录下新建ivysettings.xml; 

3、在项目根目录下新建ivy.xml,内容根据项目需要来; 

4、修改你原来的build.xml,如下:

 

Java代码

增加ivy需要的属性:   

<property name="publish.version" value="0.1" />   

<property name="ivy.report.todir" value="build" />   

<property name="repository.dir" value="d:/Local_Repository" />   

 

初始化ivy:   

<ivy:settings file="ivysettings.xml" />   

 

添加resolve target,用于下载依赖包:   

<target name="resolve" description="--> resolve and retrieve dependencies with ivy">   

        <ivy:resolve file="ivy.xml" conf="*" />   

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

</target>   

 

让原来的compile依赖于resolve:   

<target name="compile" depends="resolve">

 

添加publish target,这个不是必须的:   

<target name="publish" depends="jar" description="publish">   

        <ivy:publish resolver="local" pubrevision="${publish.version}" overwrite="true">   

            <artifacts pattern="dist/[artifact].[ext]" />   

        </ivy:publish>   

        <echo message="project ${ant.project.name} released with version ${publish.version}" />   

</target>   

 

添加report target用于生产漂亮的依赖报告,当然这个也不是必须的:   

<target name="report" depends="resolve" description="--> resolve and retrieve dependencies with ivy">   

        <ivy:report />   

</target>  

 

完整的build.xml示例见http://code.google.com/p/smartpagination/source/browse/trunk/build.xml 

 

Over! 

 

至此,你已经为蚂蚁插上了Ivy的翅膀,下面的工作只是锦上添花而已——在Eclipse配置Ivy,这个工作的作用是把ivy.xml变成classpath的一部分,使得我们只需要维护ivy.xml不需要维护.classpath文件。 

配置步骤: 

1、Window->preference->ant->RunTime->Classpath->Ant Home Entries, 

右边Add External Jars,添加org.apache.ivy_2.1.0.cr1_20090319213629.jar。 

2、安装Ivy插件:Help->Install new software->add, 

Name: IvyDE,Location: http://www.apache.org/dist/ant/ivyde/updatesite 

安装成功后重启eclipse; 

3、重启eclipse后,Window->preference->ivy->settings 

Ivy settings path设为d:/workspace/ivysettings.xml(这个值取决于你的环境) 

 

至此,Eclipse的ivy插件配置好了,然后就可以为你的项目classpath添加ivy依赖了: 

选中项目->右键 属性->Java Build Path->Libraries->Add Library...->IvyIDE Managed Dependencies->finish->OK 

然后神奇的事情就出现了——虽然你一个jar包也没下载,只是在ivy.xml里面声明了一下,但是你的项目已经可以编译通过了,就好像那些第三方类库已经在你本地了一样。

 

============================================================

 

可以任意转载, 转载时请务必以超链接形式标明文章原文出处 , 即下面的声明.

 

原文出处:http://blog.chenlb.com/2009/02/apache-ant-ivy-quick-start.html

Ivy是一个免费基于Java的依赖管理器。它提供了一些强大的功能包括依赖传递,ant集成, maven存储库兼容,持续集成,html报告等

下载ivy 2.0 http://ant.apache.org/ivy/download.cgi ,校内镜像:http://labs.xiaonei.com/apache-mirror/ant/ivy/2.0.0/apache-ivy-2.0.0-bin-with-deps.zip

下载好后安装它,把它解压到f:/ivy-2.0.0(把此目录认为是IVY_HOME),把IVY_HOME/ivy-2.0.0.jar放到 ANT_HOME/lib目录下。然后命令行入到IVY_HOME/src/example/hello-ivy目录,运行ant。然后它会下载依赖的所 有jar包。

看下hello-ivy的依赖配置:

  1. < ivy-module   version = "2.0" >   
  2.     < info   organisation = "org.apache"   module = "hello-ivy" />   
  3.     < dependencies >   
  4.         < dependency   org = "commons-lang"   name = "commons-lang"   rev = "2.0" />   
  5.         < dependency   org = "commons-cli"   name = "commons-cli"   rev = "1.0" />   
  6.     </ dependencies >   
  7. </ ivy-module >   
  1. <ivy-module version="2.0">  
  2.     <info organisation="org.apache" module="hello-ivy"/>  
  3.     <dependencies>  
  4.         <dependency org="commons-lang" name="commons-lang" rev="2.0"/>  
  5.         <dependency org="commons-cli" name="commons-cli" rev="1.0"/>  
  6.     </dependencies>  
  7. </ivy-module>  

依赖commons-lang-2.0.jar 和 commons-cli-1.0.jar,ivy会自动下载,当然还有这些*.jar所依赖的jar, 如这里的commons-cli-1.0.jar依赖commons-logging-1.0.jar,不用在ivy.xml文件定义。它们已经在lib 目录下了。

然后你再一次运行ant,ivy不会再下载这些jar,因为本地有缓存了。

当然也可以用ant report任务,输出jar依赖报告,默认在build目录,org.apache-hello-ivy-default.html。

延伸:默认缓存目录为${user.home}/cache。你也可以改它的默认目录在运行ant时,设置,如ivy.default.ivy.user.dir=f:/ivy2,所以它会缓存到f:/ivy2/cache。

ant -Divy.default.ivy.user.dir=f:/ivy2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值