Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get classloader for a bundle in equinox?

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?

like image 959
Suraj Chandran Avatar asked Oct 01 '09 11:10

Suraj Chandran


2 Answers

In OSGi 4.3 you can use:

bundle.adapt(BundleWiring.class).getClassLoader()
like image 149
Balazs Zsoldos Avatar answered Oct 01 '22 20:10

Balazs Zsoldos


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.

like image 30
SteveD Avatar answered Oct 01 '22 19:10

SteveD