Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Bundle ClassLoader
Bundle ClassLoader [message #444805] Tue, 21 February 2006 08:10 Go to next message
Eclipse UserFriend
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 #444808 is a reply to message #444805] Tue, 21 February 2006 08:41 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Bundle ClassLoader [message #444809 is a reply to message #444805] Tue, 21 February 2006 08:42 Go to previous message
Eclipse UserFriend
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
>
>
Previous Topic:How do I document an eclipse rcp?
Next Topic:Running an RCP outside Eclipse
Goto Forum:
  


Current Time: Tue Jun 24 04:20:31 EDT 2025

Powered by FUDForum. Page generated in 0.23028 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top