以编程方式启动 OSGi (Equinox)?
我希望能够轻松启动 OSGi 框架(最好是 Equinox)并从 java main 加载我的 pom 中列出的任何包。
这可能吗?如果是这样,怎么办?
似乎 pax 工具可以做到这一点,但我似乎找不到任何表明这一点的文档。我知道我可以像这样启动 Equinox:
BundleContext context = EclipseStarter.startup( ( new String[] { "-console" } ), null );
但我想做更多 - 就像我说的:加载更多包,也许启动一些服务等。
I'd like to be able to easily start an OSGi framework (preferably Equinox) and load up any bundles listed in my pom from a java main.
Is this possible? If so, how?
It seems like the pax tools would do this, but I can't seem to find any documentation indicating such. I know I can start up Equinox like so:
BundleContext context = EclipseStarter.startup( ( new String[] { "-console" } ), null );
But I'd like to do more - like I said: load more bundles in, maybe start some services, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何 OSGi 框架(R4.1 或更高版本)都可以使用
FrameworkFactory
API 以编程方式启动:OSGi 框架现在正在运行。由于
Framework
扩展了Bundle
,您可以调用getBundleContext
并调用所有常规 API 方法来操作包、注册服务等。例如最后您应该简单地等待框架关闭:
重申一下,这种方法适用于任何 OSGi 框架,包括 Equinox 和 Felix,只需将框架 JAR 放在类路径上即可。
Any OSGi framework (R4.1 or later) can be started programmatically using the
FrameworkFactory
API:The OSGi framework is now running. Since
Framework
extendsBundle
you can callgetBundleContext
and call all of the normal API methods to manipulate bundles, register services, etc. For exampleFinally you should simply wait for the framework to shutdown:
To reiterate, this approach works for any OSGi framework including Equinox and Felix just by putting the framework JAR on the classpath.
这个线程可能有点陈旧,但无论如何......
Pax 对 maven url 具有出色的支持,它甚至有一个包装 url 处理程序,允许您动态地将非 osgi jar 转换为漂亮整洁的包。
http://wiki.ops4j.org/display/paxurl/Mvn+Protocol
该命令将是:
注意:先有鸡还是先有蛋的情况 - 您必须首先使用 file: url 处理程序安装它们,或者将它们放入 autodeploy 目录中。
Karaf 将这一切都内置到了它的发行版中,所以也许看看 Karaf 启动器源代码?
第二个注意事项:通过将 @snapshots 附加到存储库 URL 来启用部署快照,通过 ConfigAdmin 管理配置
在管理所有 POM 定义的依赖项方面,请查看 Karaf 功能 - 有一个插件可以生成功能 XML 文件,该文件然后可用于部署整个应用程序:
http://karaf.apache.org/manual/2.1。 99-SNAPSHOT/developers-guide/features-maven-plugin.html
此外,这个 XML 工件可以部署到您的 OBR,因此您可以采用普通 Felix/Equinox/Karaf 设置,添加 mvn url 处理程序并使用您公司的 mvn 存储库进行配置,然后配置整个应用程序 =)
This thread might be a bit stale, but anyway...
Pax has excellent support for maven urls, it even has a wrap url handler allowing you to dynamically convert non-osgi jar to nice tidy bundles.
http://wiki.ops4j.org/display/paxurl/Mvn+Protocol
The command would then be:
Note: chicken-egg scenario - you have to install these using a file: url handler first or put them into an autodeploy directory.
Karaf has this all build in to it's distro, so maybe have a look at Karaf launcher source?
2nd note: deploying snapshots are enable by appending @snapshots to the repo URL, configuration is managed via ConfigAdmin
In terms of managing all your POM defined dependencies have a look at Karaf features - there's a plugin that would enable to generate a features XML file which can then be used to deploy your entire app:
http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/features-maven-plugin.html
Further more this XML artifact can be deployed to your OBR, so you can take a vanilla Felix/Equinox/Karaf setup, add the mvn url handler and configure with your company's mvn repo then provision the entire app =)
编辑:意识到你想从java内部开始。为我没有仔细阅读而感到羞耻
查看此链接。
http://www.eclipsezone.com/eclipse/forums/t93976.rhtml
本质上
编辑:Maven
似乎 https:// groups.google.com/group/spring-osgi/web/maven-url-handler?pli=1 包含一个 OSGi URl 处理程序服务,该服务可以采用以下格式的 URL 并从中加载包 ( mvn:/ /repo/bundle_path )
Edit: Realized you wanted to start from inside java. Shame on me for not reading close enough
Check out this link.
http://www.eclipsezone.com/eclipse/forums/t93976.rhtml
Essentially
Edit: Maven
It seems that https://groups.google.com/group/spring-osgi/web/maven-url-handler?pli=1 contains an OSGi URl Handlers Service that can take URLS of the following format and load bundles from them ( mvn://repo/bundle_path )