简体   繁体   English

以编程方式启动OSGi文件夹捆绑包

[英]Programmatically start an OSGi folder bundle

I've created a OSGi Bundle Project in Eclipse and I want to start it programmatically from another Java Project. 我已经在Eclipse中创建了OSGi Bundle项目,并且希望从另一个Java项目中以编程方式启动它。

This is what I'm trying to do: 这就是我想要做的:

FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String,String> config = new HashMap<String,String>();
Framework framework = frameworkFactory.newFramework(config);
framework.start();
BundleContext context = framework.getBundleContext();
Bundle bundle = context.installBundle("file:./test.ServiceA");
bundle.start();

but I have this error 但是我有这个错误

Exception in thread "main" org.osgi.framework.BundleException: Error loading bundle activator.
...
Caused by: java.lang.ClassNotFoundException: test.servicea.Activator cannot be found by test.ServiceA_1.0.0.qualifier

everything works if I install the plugin jar instead of point to the folder 如果我安装插件jar而不是指向文件夹,则一切正常

Bundle bundle = context.installBundle("file:./tmp/test.ServiceA_1.0.0.201504172035.jar");       

but I would like to debug directly the Eclipse project folder. 但我想直接调试Eclipse项目文件夹。

Anyone is able to help me? 有人可以帮助我吗?

Put "reference:" to the beginning of the URL. 在网址的开头放置“引用:”。 By doing that 通过这样做

  • The content of the bundle will not be copied to the working (or cache) folder of the OSGi container but it will be used from its original location 捆绑软件的内容不会复制到OSGi容器的工作(或缓存)文件夹中,但将从其原始位置使用
  • Folders can be installed as OSGi bundles 文件夹可以作为OSGi捆绑包安装

This is not part of the specification but works in Equinox and Felix (and probably in Knopflerfish as well) 这不是规范的一部分,但可以在Equinox和Felix中使用(可能还可以在Knopflerfish中使用)

Based on your example: 根据您的示例:

Bundle bundle = context.installBundle("reference:file:./test.ServiceA");

Edit based on comments 根据评论进行编辑

As the MANIFEST.MF file is in ./test.ServiceA but the compiled classes are under ./test.serviceA/bin , the "Bundle-Classpath: bin" MANIFEST header must be provided temporary until the bundle is installed from the folder. 由于MANIFEST.MF文件是在./test.ServiceA但已编译的类是./test.serviceA/bin,下的“捆类路径:BIN”,直到束从该文件夹安装必须提供清单头暂时的。 Before the release, the header must be removed as the classes will be in the root of the generated JAR. 在发布之前,必须删除标头,因为这些类将位于生成的JAR的根目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM