Bourbon_7
Bourbon_7

Reputation: 351

How to get the Bundle object which represents a fragment bundle?

I tried the following code in the fragment bundle

Bundle bundle = FrameworkUtil.getBundle( getClass() ) ;

but the bundle object still represents the host bundle, how to get the Bundle object representing the fragment bundle ?

Upvotes: 1

Views: 167

Answers (1)

BJ Hargrave
BJ Hargrave

Reputation: 9384

Classes are always loaded by the host bundle. So it is not possible to get a Bundle object for a fragment which contains a class using FrameworkUtil.getBundle(Class).

Given the host Bundle object, you can then find the attached fragments. See https://docs.osgi.org/specification/osgi.core/8.0.0/framework.wiring.html#d0e13920.

Upvotes: 1

Related Questions