How can I get the classloader for a osgi bundle in eclipse equinox setup. Thanks, Suraj
+2
A:
The short answer (certainly for OSGi 4.1, not sure of 4.2) is you can't get a bundle's classloader. However the Bundle
interface exposes a loadClass()
method and this would allow you to write a classloader that wraps the bundle API and delegates to that loadClass()
method. Or you can save some time and use Spring DM's BundleDelegatingClassLoader
class instead.
hbunny
2009-10-01 13:42:03
A:
In normal java code, you can get the class loader that loaded a given object with
object.getClass().getClassLoader();
Or even just
SomeType.class.getClassLoader();
The same applies to Equinox, just use an object or type that comes from the bundle you are interested in.
Andrew Niefer
2009-10-02 02:44:16