How to get classloader for a bundle in equinox?

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.

Up vote 1 down vote favorite share g+ share fb share tw.

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? Eclipse osgi classloader bundle equinox link|improve this question edited Jul 26 '11 at 14:08 asked Oct 1 '09 at 11:13Suraj Chandran7,88411529 84% accept rate.

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.

But then you have a bootstrapping problem. How do you get that first instance? – Geniedesalpages Feb 24 '11 at 13:44 If you have dependency on the other bundle, you can refer to the other class directly (SomeType.

Class) the osgi classloaders delegate between bundles so it still comes from the other classloader. If you don't have a dependency you need to get the Bundle object (using PackageAdmin) and use Bundle#loadClass as mentioned in the other answer. – Andrew Niefer Feb 27 '11 at 2:09.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions