2

I want to programmatically retrieve all the bundles that are loaded. In an older version we were using it in this fashion:

    Field osgiField = EclipseStarter.class.getDeclaredField("osgi"); 
    osgiField.setAccessible(true);
    final org.eclipse.osgi.framework.internal.core.OSGi osgi =
          (org.eclipse.osgi.framework.internal.core.OSGi) osgiField.get(null);
    osgi.getBundleContext().getBundles();

How to retrieve all the loaded bundles in the latest osgi?

Hilikus
  • 9,954
  • 14
  • 65
  • 118
bhar
  • 67
  • 2

1 Answers1

2

From a bundle you can either implement the BundleActivator interface and mark your class in the Manifest as "BundleActivator:my.ClassName".

Or if that is not possible you can use FrameworkUtil.getBundle(this.getClass()).getBundleContext().

Also see this question: Best technique for getting the OSGi bundle context?

Then use bundleContext.getBundles();

These approaches should work with any OSGi framework.

Community
  • 1
  • 1
Christian Schneider
  • 19,420
  • 2
  • 39
  • 64