Skip to main content
Oct 16, 2015 2:27 AM UTC
Solved

How to communicate with different OSGI bundles

Hi there,

I define a osgi bundle A, and the second osgi bundle B, now a method in the A need to call another mothod defined in the B.

private BService getBService() { BundleContext ctx = FrameworkUtil.getBundle(this.getClass()) .getBundleContext(); ServiceReference serviceReference = ctx .getServiceReference(BService.class.getName()); return BService.class.cast(ctx.getService(serviceReference)); }

In general, if bundle A want to get B instance, developer could use above code. But the question is how to make compile A bundle class successfully? because A can't reference class BService.

 

Thanks a lot.

Br,

Brian

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Adobe Employee
Oct 16, 2015 2:27 AM UTC

Hi,

BService must be exported by Bundle B.

kind regards,
Jörg

3 replies

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
Oct 16, 2015 2:27 AM UTC

Hi,

BService must be exported by Bundle B.

kind regards,
Jörg

Translate
Lokesh_Shivalingaiah
Level 10
Oct 16, 2015 2:27 AM UTC

In the pom.xml of Bundle A, add

           

<dependency> <groupId>[GroupId of Bundle B as mentioned in its pom.xml]</groupId> <artifactId>[ArtifactId of Bundle B]</artifactId> <version>[Version of Bundle B]</version> </dependency>
Translate
Adobe Employee
Oct 16, 2015 2:27 AM UTC

You should add the B bundle as a dependency to A bundles pom file

Translate