Bundle ClassLoader [message #444805] |
Tue, 21 February 2006 08:10  |
Eclipse User |
|
|
|
I know how to load a class/resource using the Bundle API, but I'm using a
third-party tool (spring) that wants me to pass it the ClassLoader object.
What I do is use the bundle api to load some (arbitrary) class that is
defined in the bundle, and then get the class loader from that Class object.
However, that seems like a workaround, and it requires me to maintain the
additional piece of information (the name of the arbitrary class, instead of
just the bundle id). Is there any way to get the ClassLoader object from
the Bundle? If not, is that a "bug" - because that's a pretty big gap in
its capabilities.
Thanks!
Jacob Robertson
|
|
|
|
Re: Bundle ClassLoader [message #444809 is a reply to message #444805] |
Tue, 21 February 2006 08:42  |
Eclipse User |
|
|
|
Hi Jacob,
you cannot get the classloader for a bundle by its id. Because a each
time a Bundle is loaded it is loaded by a new classloader. This is the
only way that java allows for a class with the same name to be loaded again.
So you can only get the classloader for a bundle after it is loaded.
Next time it is loaded it would be another classloader instance. If you
wanted to get the classloader ahead of time, before the bundle is
loaded, that wouldn't make sense either, since in that case OSGI would
need to pre-instantiate classloaders it might not even use later on. Not
a nice thing...
Once the bundle is loaded you can get the classloader from any class
object of the bundle. Eg by calling
YourBundleActivator.class.getClassLoader(),
someInstanceOfClassInBundle.getClass().getClassLoader() and so on.
This is my understanding of things.
Regards,
Stepan Rutz
> I know how to load a class/resource using the Bundle API, but I'm using a
> third-party tool (spring) that wants me to pass it the ClassLoader object.
> What I do is use the bundle api to load some (arbitrary) class that is
> defined in the bundle, and then get the class loader from that Class object.
> However, that seems like a workaround, and it requires me to maintain the
> additional piece of information (the name of the arbitrary class, instead of
> just the bundle id). Is there any way to get the ClassLoader object from
> the Bundle? If not, is that a "bug" - because that's a pretty big gap in
> its capabilities.
>
> Thanks!
> Jacob Robertson
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.23028 seconds