首页 文章

从嵌入式OSGi框架中消费服务

提问于
浏览
0

我有可嵌入的菲利克斯 . 我有一些API包和Impl . API导出接口 C .Impl导入该接口并在激活器中注册impl . 现在我想得到C impl otside OSGi

FrameworkFactory ff = new FrameworkFactory();
  ...
  BundleContext bc = fwk.getBundleContext();
  ...
  final ServiceReference[] serviceReferences = bc.getServiceReferences(C.class.getName(), "(objectclass=" + C.class.getName() + ")");
  for(ServiceReference serviceReference : serviceReferences){
     final Object service = bc.getService(serviceReference);
     ...
  }

现在我想与它互动 . 我可以用反射来做

System.out.println(service.getClass().getMethod("some").invoke(service)); //using

但我无法施展它

System.out.println(service instanceof C); //prints false

我想这来自不同的ClassLoaders . 但我怎么解决呢?我们如何从外部与OSGi环境相互作用?或者我们可以将它全部放入OSGi容器中?

1 回答

  • 5

    如果要嵌入OSGi,则服务的API(即接口“C”)必须对外部应用程序可见,并通过系统束导出导出到OSGi中 . 外部应用程序无法从OSGi框架内包含的包中导入包 .

相关问题