I have read a lot of equinox code for this, but still can't figure out a non-hacky way of getting the classloader for a osgi bundle in eclipse equinox setup. Is there one?
In OSGi 4.3 you can use:
bundle.adapt(BundleWiring.class).getClassLoader()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With