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

139 Views Asked by At

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 ?

1

There are 1 best solutions below

0
On

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.