Search code examples
osgi-bundle

How to make OSGi bundle which uses methods from another bundle?


I have a preveously created bundle "A" which contains some methods(registred as services). And now I want to create another bundle "B" which uses methods from "A". As I understand it, I should getServiceReference() from class containing those methods in "B" activator. But how can I get access to to those class? Should I import project with "A" as library or import a .jar file to "B" project? Im reading "OSGI in action", but couldn't find clear answer there. Can you answer or advice some article that will help to find an answer, please.
P.S. Im using Inteleji IDEA IDE.


Solution

  • The bundle A should export the package where the A class is located, this is done by adding a "Export-Package" field to the Manifest.

    The bundle B should import the package where the A class is located, this is done by adding a "Import-Package" field to the Manifest.

    The bundle A should register A as a service.

    The bundle B should get the service from A, and then it can call methods on the A class.

    Depending on what tools you use for the compilation (gradle/maven, bnd tools, ...), exporting and importing packages can be "automated".

    Depending on what tools you use at runtime (blueprint, iPOJO, ds, ...), register and injecting services can be "automated".