I am building some modules which I want to expose as OSGi bundles without any actual dependencies to OSGi libraries. It would seem that this is possible using the declarative services option.
However because I'm rather new to OSGi (at least on the bundle-creating side) I want to test if it all works as it should, to this end I want to set up a small embedded OSGi environment.
Currently I have a single bundle which exports an API and also provides a stub implementation of a single interface.
I have followed the following tutorials to set up an environment:
- http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html
- How to start and use Apache Felix from code?
And the embedded felix implementation seems to work properly however there are two problems:
Bundle bundle = felix.getBundleContext().installBundle("/path/to/bundle.jar")
bundle.start();
System.out.println(bundle.getRegisteredServices());
This prints out null
so while the bundle is seemingly started ok, it does not seem to expose any services.
Secondly I'm wondering whether I have to do anything special to get the declarative services bit up and running. My maven dependencies are:
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
Based on the email thread found here: http://mail-archives.apache.org/mod_mbox/felix-users/201111.mbox/%[email protected]%3E
I tried to add the bundle to the felix startup properties:
map.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.apache.felix.scr; version=1.6.2");
However this seems a bit optimistic at first glance. How do I enable the declarative services for an embedded felix engine?