Search code examples
javaooposgibundleclassloader

How to get Bundle Object from ClassLoader? (Java, OSGI)


I'm working on some old code which depends on:

import org.eclipse.osgi.framework.adaptor.BundleClassLoader;

and uses it here:

protected Bundle getBundle() {
    BundleClassLoader cl = (BundleClassLoader) editor.getClass().getClassLoader();
    return cl.getBundle();
}

Is there a new way to do this? (Retrieve the bundle from the ClassLoader) I'm not finding any resources on this change. BundleClassLoader seems to have been deprecated..


Solution

  • You can use FrameworkUtil.

     Bundle b = FrameworkUtil.getBundle( editor.getClass() );