以编程方式使用IVY依赖关系管理器 [英] using IVY dependencies manager programmatically

查看:123
本文介绍了以编程方式使用IVY依赖关系管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助使用IVY作为依赖关系管理器

我的应用程序需要在RUN-TIME加载插件

意味着在核心应用程序运行时,用户可以请求一个新插件

并安装它们,

i希望使用核心应用程序数据库管理所有已安装的插件。我想从我的插件服务器(或其他描述符)获取一个pom,

并请求IVY告诉我什么是依赖关系,或者让IVY
根据我的应用程序的当前状态安装插件和依赖项



(我现在有什么,

1.jar由核心应用程序使用

2.jar由当前安装的插件使用)



我希望每个插件在我的应用程序所在的某个文件夹(不是共享文件夹)下具有独立目录



我不知道从哪里开始

i注意到没有编程API



我找到一个人的网络上的一个链接,尝试类似的

但看起来像代码没有完成,或一些变量缺少
,我不知道如何完成休息的编程文档湖

http://www.mail-archive.com/ivy-user@ant.apache.org/msg03228.html
(其中变量艺术来自.....)



你可以帮我吗...
谢谢所有的



更新




i我得到一些错误加上我不知道如何定义我的archiva服务器

  IvySettings settings = new IvySettings() ; 

settings.setDefaultIvyUserDir(new File(D:/ programming / eclipse_projects / ivyTest / repo /));

settings.setDefaultCache(new File(D:/ programming / eclipse_projects / ivyTest / repo / cache /));
settings.setDefaultCacheArtifactPattern([module] / [revision] / [module] - [revision]( - [classifier]);

Ivy ivy = Ivy.newInstance(settings)

ivy.getLoggerEngine()。pushLogger(new DefaultMessageLogger(Message.MSG_VERBOSE));

ModuleDescriptor md = PomModuleDescriptorParser.getInstance()。parseDescriptor(new IvySettings(),new文件(src / movies.pom)toURL(),true);

RetrieveOptions retriveOptions = new RetrieveOptions();
retriveOptions.setUseOrigin(true);
retriveOptions .setConfs(md.getConfigurationsNames());
ivy.retrieve(md.getModuleRevisionId(),lib / [conf] / [artifact]。[ext],etriveOptions);

这是我得到的错误

  :: loading settings :: url = jar:file:/ D:/programming/eclipse_projects/ivyTest/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml 
:: retrieve :: org.jtpc#movies
checkUpToDate = true
confs:[default,master,comp ile,提供,运行时,测试,系统,源,javadoc,可选]
java.lang.RuntimeException:检索org.jtpc时出现问题#movies:java.lang.IllegalStateException:报告文件'D:\programming \eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml'不存在。
在org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:206)
在org.apache.ivy.Ivy.retrieve(Ivy.java:540)
在Test.main(Test.java:52)
导致:java.lang.IllegalStateException:报告文件'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc- movies-default.xml'不存在。
在org.apache.ivy.plugins.report.XmlReportParser.parse(XmlReportParser.java:294)
在org.apache.ivy.core.retrieve.RetrieveEngine.determineArtifactsToCopy(RetrieveEngine.java:288)
在org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:104)
... 2更多


解决方案

常春藤可以用作独立的Java程序:

  java -jar ivy.jar -retrievelib / [conf] / [artifact]。[ext]

检索用于确定文件的安装位置,基于ivy配置设置

  $ find lib -type f 
lib / core / commons-lang.jar
lib / plugin1 / commons-logging.jar
lib / plugin1 / commons-codec.jar
lib / plugin2 / commons-logging.jar
lib / plugin2 / commons-cli.jar
lib / plugin3 / commons-logging.jar

配置用作集合标签或依赖关系的分组。它们类似于Maven范围,但更灵活:

 < ivy-module version =2.0> 
< info organization =com.myspotonthewebmodule =demo/>
<配置>
< conf name =coredescription =核心应用程序依赖关系/>
< conf name =plugin1description =Plugin 1 dependencies/>
< conf name =plugin2description =Plugin 2 dependencies/>
< conf name =plugin3description =Plugin 3 dependencies/>
< / configurations>
<依赖关系>
< dependency org =commons-langname =commons-langrev =2.5conf =core-> default/>
< dependency org =commons-codecname =commons-codecrev =1.4conf =plugin1-> default/>
< dependency org =commons-cliname =commons-clirev =1.2conf =plugin2-> default/>
< dependency org =commons-loggingname =commons-loggingrev =1.1.1conf =plugin1,plugin2,plugin3-> default/>
< / dependencies>
< / ivy-module>

如果您只想下载并安装一组jar,可以在指定的目录中使用 confs 参数:

  java -jar ivy.jar -retrieveplugin1 / [artifact] ext]-confs plugin1 

最后,如果您仍然想使用编程API,可以调用主要调用的运行方法



http://svn.apache.org/viewvc/ant/ivy/core/trunk/src /java/org/apache/ivy/Main.java?view=markup



更新1



Groovy已经建立了对调用ivy任务的支持

  import groovy.xml.NamespaceBuilder 

def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant,'antlib:org.apache.ivy.ant')

ivy.settings(file:ivysettings.xml )
ivy .retrieve(pattern:lib / [conf] / [artifact]。[ext])
ivy.report(toDir:'reports',graph:false)



更新2



要设置本地Maven存储库的位置,您需要使用 ivysettings.xml 文件。

 < ivysettings> 
< settings defaultResolver ='nexus'/>
< resolvers>
< ibiblio name ='nexus'root ='http://myhost.mydomanin.com:8081 / nexus'm2compatible ='true'/>
< / resolvers>
< / ivysettings>



更新3



详细说明如何从Java调用Ivy


i need help using IVY as dependencies manager
my application need to load plug-ins at RUN-TIME
means while the core application is running ,user can request for a new plug-in
and install them ,
i wish to manage all installed plug-ins using the core application DB.

i want to get a pom from my plug-ins server (or some other descriptor),
and ask IVY to tell me what are the dependencies OR let IVY install the plug-in and dependencies , based on the current state of my application.

( what do i have right now ,
1.jar's used by core application
2.jar's used by current installed plug-ins)

i wish for each plug-in to have independent directory
under some folder where my application is located (not a shared one)

the thing is i don't know where to start
i notice that there is no programming API for that

i located one link over the network of someone who try something similar
but look likes the code is not completed , or some variable are missing and i dont know how to complete the rest cause lake of programming documentation
http://www.mail-archive.com/ivy-user@ant.apache.org/msg03228.html (where the variable "art" came for.....)

can you help me please ... Thank you all

UPDATE

ok this what i am trying now . i am getting some a error plus i dont know how to define my archiva server

      IvySettings settings = new IvySettings();

     settings.setDefaultIvyUserDir(new File("D:/programming/eclipse_projects/ivyTest/repo/"));

      settings.setDefaultCache(new File("D:/programming/eclipse_projects/ivyTest/repo/cache/"));
      settings.setDefaultCacheArtifactPattern("[module]/[revision]/[module]-[revision](-[classifier]");

  Ivy ivy = Ivy.newInstance(settings);

  ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_VERBOSE));

  ModuleDescriptor md =  PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), new File("src/movies.pom").toURL(), true);

  RetrieveOptions retriveOptions = new RetrieveOptions();
  retriveOptions.setUseOrigin(true);
  retriveOptions.setConfs(md.getConfigurationsNames());
  ivy.retrieve(md.getModuleRevisionId(), "lib/[conf]/[artifact].[ext]", etriveOptions);

this is the error i get

:: loading settings :: url = jar:file:/D:/programming/eclipse_projects/ivyTest/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: retrieving :: org.jtpc#movies
    checkUpToDate=true
    confs: [default, master, compile, provided, runtime, test, system, sources, javadoc, optional]
java.lang.RuntimeException: problem during retrieve of org.jtpc#movies: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
    at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:206)
    at org.apache.ivy.Ivy.retrieve(Ivy.java:540)
    at Test.main(Test.java:52)
Caused by: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
    at org.apache.ivy.plugins.report.XmlReportParser.parse(XmlReportParser.java:294)
    at org.apache.ivy.core.retrieve.RetrieveEngine.determineArtifactsToCopy(RetrieveEngine.java:288)
    at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:104)
    ... 2 more

解决方案

Ivy can be used as a standalone java program:

java -jar ivy.jar -retrieve "lib/[conf]/[artifact].[ext]"

The retrieve pattern can be then used to determine where files are installed, based on the ivy configuration settings

$ find lib -type f
lib/core/commons-lang.jar
lib/plugin1/commons-logging.jar
lib/plugin1/commons-codec.jar
lib/plugin2/commons-logging.jar
lib/plugin2/commons-cli.jar
lib/plugin3/commons-logging.jar

Configurations are used as a collective label or grouping of dependencies. They are similar to Maven scopes but much more flexible:

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>
    <configurations>
        <conf name="core"    description="Core application dependencies"/>
        <conf name="plugin1" description="Plugin 1 dependencies"/>
        <conf name="plugin2" description="Plugin 2 dependencies"/>
        <conf name="plugin3" description="Plugin 3 dependencies"/>
    </configurations>
    <dependencies>
        <dependency org="commons-lang"    name="commons-lang"    rev="2.5"   conf="core->default"/>
        <dependency org="commons-codec"   name="commons-codec"   rev="1.4"   conf="plugin1->default"/>
        <dependency org="commons-cli"     name="commons-cli"     rev="1.2"   conf="plugin2->default"/>
        <dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="plugin1,plugin2,plugin3->default"/>
    </dependencies>
</ivy-module>

If you only want to download and install one set of jars, into a specified directory you can use the confs parameter:

java -jar ivy.jar -retrieve "plugin1/[artifact].[ext]" -confs plugin1

Finally, if you still want to use a programming API, you could invoke the run method called by the main class

http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=markup

Update 1

Groovy has built in support for invoking ivy tasks

import groovy.xml.NamespaceBuilder

def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ivy.ant')

ivy.settings(file:"ivysettings.xml")
ivy.retrieve(pattern:"lib/[conf]/[artifact].[ext]")
ivy.report(toDir:'reports', graph:false) 

Update 2

To set the location of your local Maven repository you need to use an ivysettings.xml file.

<ivysettings>
  <settings defaultResolver='nexus' />
  <resolvers>
    <ibiblio name='nexus' root='http://myhost.mydomanin.com:8081/nexus' m2compatible='true' />
  </resolvers>
</ivysettings>

Update 3

Just found an article that details how to invoke Ivy from Java

这篇关于以编程方式使用IVY依赖关系管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆