Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would caution against taking this approach. An OSGi framework can contain multiple providers or versions of a package. Trying to make a unified class loader that correctly copes with this is not trivial. However if you want to query the packages being exported you have two options depending on which version of OSGi you are using.</p> <p>If you are using OSGi prior to OSGi R4.3 you can use <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/packageadmin/PackageAdmin.html" rel="nofollow">PackageAdmin</a>. This is a service registered in the service registry that allows you to query what packages are exported by bundles in the framework. Of specific interest to you will be the <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/packageadmin/PackageAdmin.html#getExportedPackage%28java.lang.String%29" rel="nofollow">getExportedPackage</a> method. This allows you to select a provider of the package and then you can call loadClass on the bundle that provides the package.</p> <p>PackageAdmin is deprecated in R4.3 (although equinox still implements it). This is more complicated. To do what you desire you need to make use of the new <a href="http://www.osgi.org/javadoc/r4v43/org/osgi/framework/wiring/BundleWiring.html" rel="nofollow">BundleWiring</a> API. This involves getting hold of each bundle in the system and do the following:</p> <pre><code>BundleWiring bw = bundle.adapt(BundleWiring.class); List&lt;BundleCapability&gt; capabilities = bw.getCapabilities(BundleRevision.PACKAGE_NAMESPACE); for (BundleCapability bc : capabilities) { String pkg = bc.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE); } </code></pre> <p>in this you case need to cope with multiple providers and select the correct one. Working out the correct one is the hard part.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload