Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to communicate with different OSGI bundles

Anonymous
Not applicable

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

1 Accepted Solution
Jörg_Hoh
Correct answer by
Employee
Employee

Hi,

BService must be exported by Bundle B.

kind regards,
Jörg

View solution in original post

0 Replies
kalyanar
Employee
Employee

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

bsloki
Community Advisor
Community Advisor

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>
Jörg_Hoh
Correct answer by
Employee
Employee

Hi,

BService must be exported by Bundle B.

kind regards,
Jörg

View solution in original post