问题描述
我需要帮助使用 IVY 作为依赖项管理器
我的应用程序需要在运行时加载插件
意味着当核心应用程序运行时,用户可以请求一个新的插件
并安装它们,
我希望使用核心应用程序 DB 管理所有已安装的插件.
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.
我想从我的插件服务器(或其他一些描述符)获取一个 pom,
并让 IVY 告诉我依赖项是什么或让 IVY安装插件和依赖项,基于我的应用程序的当前状态.
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 IVYinstall the plug-in and dependencies ,based on the current state of my application.
(我现在有什么,
1. 核心应用程序使用的jar
2.jar 被当前安装的插件使用)
( 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)
问题是我不知道从哪里开始
我注意到没有编程 API
the thing is i don't know where to start
i notice that there is no programming API for that
我在网络上找到了一个尝试类似方法的人的链接
但看起来代码没有完成,或者缺少一些变量而我不知道如何完成剩下的编程文档湖
http://www.mail-archive.com/[email protected]/msg03228.html(变量艺术"的来源......)
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 missingand i dont know how to complete the rest cause lake of programming documentation
http://www.mail-archive.com/[email protected]/msg03228.html(where the variable "art" came for.....)
你能帮我吗...谢谢大家
can you help me please ...Thank you all
更新
好的,这就是我现在正在尝试的.我遇到了一些错误,而且我不知道如何定义我的档案服务器
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);
这是我得到的错误
:: 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:programmingeclipse_projectsivyTest
epocacheorg.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:programmingeclipse_projectsivyTest
epocacheorg.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 可以作为 独立使用 java程序:
Ivy can be used as a standalone java program:
java -jar ivy.jar -retrieve "lib/[conf]/[artifact].[ext]"
然后可以使用 检索 模式根据 ivy 配置设置确定文件的安装位置
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
配置用作集合标签或依赖项分组.它们类似于 Maven 范围,但更加灵活:
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>
如果只想下载并安装一组jar包,可以使用confs参数:
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
最后,如果你还想使用编程API,你可以调用主类调用的run方法
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
Groovy 内置了对调用 ivy 任务的支持
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)
更新 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
这篇关于以编程方式使用 IVY 依赖项管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!