|
Re: Bundle ClassLoader [message #444808 is a reply to message #444805] |
Tue, 21 February 2006 13:41 |
|
Jacob Robertson wrote:
> 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
>
>
In this message there is a convenience function that gets the
classloader from a bundle (basically, the same way you described but
using the MANIFEST headers so you don't have to guess at a class)
http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/m sg02875.html
Other than that I would 1) search google with something like
"site:dev.eclipse.org news.eclipse get bundle classloader" and 2) post
your question to the eclipse.technology.equinox newsgroup.
Later,
PW
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Re: Bundle ClassLoader [message #444809 is a reply to message #444805] |
Tue, 21 February 2006 13:42 |
user Messages: 296 Registered: July 2009 |
Senior Member |
|
|
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.03844 seconds