ClassLoader issue: Loading classes of other bundles [message #106123] |
Tue, 11 March 2008 08:06  |
Eclipse User |
|
|
|
Hi,
I encountered a ClassLoader problem. I try to explain my problem the most
simple way:
- There are 3 bundles (F,S,C)
- Bundle F exports a package com.abc which contains an interface FInterface
- Bundle S imports the package com.abc (from Bundle F) and provides an
implementation of FInterface in package com.sde and exports this package
- Bundle C wants to load the implementation class of FInterface from Bundle
S and therefore imports the package com.sde
- for loading the implementation of FInterface bundle C instruments the
loadClass(String name) method from the BundleContext of Bundle S
--> this is where the error occurs! I get a ClassNotFoundException which
tells me that the FInterface class could not be found
Why does this exception occur (Bundle C imports com.abc as well as com.sde)?
Is there a way to enable Bundle C to load the implementation class of
FInterface from Bundle S?
Any help or pointers are much appreciated.
Regards,
Andreas.
|
|
|
|
|
Re: ClassLoader issue: Loading classes of other bundles [message #106453 is a reply to message #106412] |
Mon, 17 March 2008 16:44  |
Eclipse User |
|
|
|
Hi Andreas,
the cleanest solution for this issue is to use the service registry.
Bundle S registers an FInterfaceImpl object under the name of FInterface
(BundleContext#registerService). Bundle C imports only the package which
hosts FInterface and queries the service registry
(BundleContext#getServiceReference).
For more information take a look at
http://www2.osgi.org/javadoc/r4/org/osgi/framework/BundleCon text.html or
ask this newsgroup :-)
Greetings,
Benedikt
Andreas Heinecke wrote:
> Hi Gunnar,
> in fact this would be maybe possible, it isn't a solution for my particular
> problem. Bundle C must not important any code from Bundle S.
> Regards,
> Andreas.
|
|
|
Powered by
FUDForum. Page generated in 0.05312 seconds