baklap
baklap

Reputation: 2173

Access class of other OSGi bundle

My project has two bundles, lets say Bundle A and Bundle B.

Now Bundle A needs to access a class from Bundle B.

How can I do that?

Upvotes: 3

Views: 2951

Answers (2)

pooh
pooh

Reputation: 662

As @earcam wrote, it is strongly recommended to use Import-Package:.

Also, always add a version to the exported package in bundle B - this is good practice that you will appreciate later when you create the next version of bundles A and B.

Upvotes: 1

thobens
thobens

Reputation: 1731

There are two ways:

  1. Add the dependency of bundle B to the Manifest of bundle A: Require-Bundle: bundle-id-of-bundle-A
  2. Import the package of the wanted class in the Manifest of bundle A: Import-Package: package.of.your.class

In both situations, you need to export the package that contains your class in bundle B: Export-Package: package.of.your.class

Also, here's a good intro: http://ctpjava.blogspot.com/2010/09/introduction-to-osgi.html

Upvotes: 6

Related Questions