我有可嵌入的Felix.我有一些API捆绑包和Impl. API导出接口C .Impl导入该接口并在激活器中注册impl.现在我要获取C隐含的OSGi
I have embeddable Felix. I have some API bundle and Impl. API exports interface C.Impl imports that interface and register impl in activator. Now I want get 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); ... }现在我想与它互动.我可以用反射来做
Now I want to interact with it. I can do it with reflection
System.out.println(service.getClass().getMethod("some").invoke(service)); //using但我无法投射
System.out.println(service instanceof C); //prints false我猜这来自不同的ClassLoader.但是我该如何解决呢?我们如何从外部与OSGi上下文进行交互?还是我们可以将其全部放入OSGi容器中?
I guess that comes from different ClassLoaders. But how I can solve it? How we can interract with OSGi context from outside? Or we can obly put it all into OSGi container?
推荐答案如果要嵌入OSGi,则该服务的API(即接口"C")必须对外部应用程序可见,并通过系统导出到OSGi捆绑出口.外部应用程序无法从OSGi框架内包含的包中导入软件包.
If you are embedding OSGi, the API for the service (i.e. interface "C") has be to visible to the outer application and exported into OSGi via the system bundle exports. The outer application cannot import packages from the bundles contained inside the OSGi framework.
更多推荐
嵌入式OSGi框架中的消费服务
发布评论