Search code examples
javaosgiapache-felix

Embedded osgi framework, how to call service functions?


I have a simple java project, called server. In addition i have a osgi api project which defines an interface BlockProvider. Next i have an osgi declarative service project with a service that implements BlockProvider.

In my java project 'server' i have an embedded osgi framework (felix in my case).

I created an bundleactivator which installs gogo osgi bundles, scr bundle , my api project bundle and the service project bundle.

Works without problem, i can inspect my service bundle.

In my server project i want to see which services implement BlockProvider interface. So i implement a ServiceTracker with "BlockProvider.class.getName()" as second parameter (the filter one).

Works also without problems, getServices() return my service project.

But here comes the catch: i can't call any of the functions on the interface BlockProvider, because the BlockProvider in the 'server' project uses a different classloader (sun.misc.Launcher$AppClassLoader@4e0e2f2a) than the service project (o: yellowblock [6]).

I suspect I'm overlooking something basic here: but how can i call functions of my BlockProvider service that implements my BlockProvider interface?


Solution

  • You can only access services from outside the OSGi framework if the API package is provided by the system bundle / the framework. So you should not install the API bundle and instead use the framework property org.osgi.framework.system.packages.extra to export your API package.