Find the OSGI bundle that exports a package?

It sounds like you want to do this programmatically, not at the Gogo shell ... at least I'll assume that from wording of your question.

There is no real way to say "which bundle" exports a given package since there can be many bundles exporting any given package and that package can be in use from many bundles by many bundles. If you have a specific bundle and you want to know which bundle provides package com.test to it, you can get the importing bundle's wiring Bundle.adapt(BundleWiring.class) and then use BundleWiring.getRequiredWires() to get the providers of all of the bundle's dependencies.

From there you just need to find the wire of osgi.wiring.package namespace for the package you want, then the provider of that wire will be a BundleCapability of a BundleRevision of the bundle you are interested in.


Recent versions of the Apache Felix OSGi console include a "dependency finder" plugin which lists the bundle(s) that export a given package or class. There are some screenshots at http://www.6dlabs.com/blog/dklco/2012-05-04/new-cq-55-dependency-finder (which mention CQ5 but the plugin does not depend on that).

That's useful at the admin level, and if you need to find that out in code you could have a look at that plugin's source code, see https://issues.apache.org/jira/browse/FELIX-3045


Have you tried: exports | grep com.test ?