java - Can't get a working reference to an OSGi service -



I try to embed Apache Felix into a simple Hello World Java project I'm Maven, but I can not find a way to get a reference to the service of a bundle. I have established the ORG.AP.F.L.X. Bandlarepositive Bundle with a jar in OSGI and it is my project Maven is also added as a dependency. After that I am starting the bundle, I am getting the bundlecontentech from it and then calling getServiceReference (repository admin.clash.gaten name ()) in the context of that bundle. What I'm unhappy with is that I have to use bundled contests with the installed bundle, if I use the framework's bundle syntax, then the context of the service will always be empty. It's not convinient.

The second, and the important issue is that when I finally get a reference to the RepositoryAdmin service from the bundlerepository bundle I can not get it molded in org.apache.felix.bundlerepository.RepositoryAdmin, execute the following code :

  (repository admin) admin.getBundleContext (). GetService (ref)  

will throw off this exception:

  java.lang.ClassCastException: org.apache.felix.bundlerepository.impl.RepositoryAdminImpl org. Can not be molded into apache.felix.bundlerepository.RepositoryAdmin  

I know that this is a classpath problem due to the type of problem and the incompatibility of the interface, but I have the same version (2.0.2), which is a Maven dependency of my project. I'm also aware of Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA OSGi configuration options which should force a bundle of using a package from the host application, but it did not help me.

The main square of my project here is messy because I was trying different things to get a reference to a service, but nobody really did not work for me.

Hope someone will help me, because I am really desperate about this issue.

Thanks for giving you some more information about what you are doing, I already have a FELIX list I have followed the fairs now I think that I understand what happens. "; Version = 2.0.2 org.apache.felix.bundlerepository"

FRAMEWORK_SYSTEMPACKAGES_EXTRA is defined by the reason that you can not find service from outside the RepositoryAdmin bundle P> repository admin Bundle does not have the same version of the package. I downloaded the bundle and looked in the manifest:

  Export-package: org.osgi.service.repository; Version = "1.0"; Usage: = "org.osg i.resource", org.apache.felix.bundlerepository; Version = "2.1", uses: = ". Org osgi.framework"  

So as you see the version you should export the system bundle from 2.1 is 2.0.2 Versions in OSGI are not defined at the bundle level per package, so while most of the time they are the same, it is not always true. Especially for OSGi spec packages.

So when the package versions are different, then you have two effects: 1. You will not be able to get a service with a separate package 2. If you receive a service object in something < / P>

So you can try the 2.1 version and if it works then can you report?

/ html>

Comments