我希望能够轻松地启动OSGi框架(最好是Equinox),并从java main加载我的pom中列出的任何包。
这个是可能的吗?如果是这样的话,是怎么做的?
似乎pax工具可以做到这一点,但我似乎找不到任何说明这一点的文档。我知道我可以像这样启动Equinox:
BundleContext context = EclipseStarter.startup( ( new String[] { "-console" } ), null );但我想做的更多--就像我说的:加载更多的包,也许启动一些服务,等等。
发布于 2011-01-13 04:51:13
任何OSGi框架(R4.1或更高版本)都可以使用FrameworkFactory API以编程方式启动:
ServiceLoader<FrameworkFactory> ffs = ServiceLoader.load(FrameworkFactory.class);
FrameworkFactory ff = ffs.iterator().next();
Map<String,Object> config = new HashMap<String,Object>();
// add some params to config ...
Framework fwk = ff.newFramework(config);
fwk.start();OSGi框架现在正在运行。由于Framework扩展了Bundle,因此您可以调用getBundleContext并调用所有常规的API方法来操作包、注册服务等。
BundleContext bc = fwk.getBundleContext();
bc.installBundle("file:/path/to/bundle.jar");
bc.registerService(MyService.class.getName(), new MyServiceImpl(), null);
// ...最后,您只需等待框架关闭:
fwk.stop();
fwk.waitForStop(0);重申一下,这种方法适用于任何 OSGi框架,包括Equinox和Felix,只需将框架JAR放在类路径上即可。
发布于 2011-03-25 02:02:35
这个帖子可能有点过时了,但不管怎样...
Pax对maven url有很好的支持,它甚至有一个包装url处理程序,允许你动态地将非osgi jar转换成漂亮整洁的bundle。
http://wiki.ops4j.org/display/paxurl/Mvn+Protocol
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-wrap</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-mvn</artifactId>
<version>1.2.5</version>
</dependency>然后,命令将是:
install -s mvn:groupId:artifactId:version:classifier注意:鸡和蛋的情况--你必须首先使用file: url处理程序安装它们,或者把它们放到一个自动部署的目录中。
Karaf在它的发行版中内置了所有这些功能,所以也许可以看看Karaf launcher的源代码?
2注意:部署快照是通过将@snapshots附加到存储库URL来实现的,配置是通过ConfigAdmin进行管理的
在管理所有POM定义的依赖项方面,请看一下Karaf功能-有一个插件可以生成功能XML文件,然后可以用它来部署整个应用程序:http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/features-maven-plugin.html
此外,还可以将此XML工件部署到您的OBR,因此您可以使用vanilla Felix/Equinox/Karaf设置,添加mvn url处理程序并使用您公司的mvn repo进行配置,然后配置整个应用程序=)
发布于 2011-01-13 04:39:50
编辑:我意识到你想从java内部开始。我真为没有仔细阅读而感到羞愧
请查看此链接。http://www.eclipsezone.com/eclipse/forums/t93976.rhtml
本质上
public static void main(String args[]) throws Exception {
String[] equinoxArgs = {"-console","1234","-noExit"};
BundleContext context = EclipseStarter.startup(equinoxArgs,null);
Bundle bundle = context.installBundle(
"http://www.eclipsezone.com/files/jsig/bundles/HelloWorld.jar");
bundle.start();
}编辑: Maven
https://groups.google.com/group/spring-osgi/web/maven-url-handler?pli=1似乎包含了一个OSGi URl处理程序服务,它可以获取以下格式的URl并从中加载包( mvn://repo/bundle_path )
https://stackoverflow.com/questions/4673406
复制相似问题