How can I make osgi find a class in an imported jar [message #329755] |
Wed, 02 July 2008 16:20  |
Eclipse User |
|
|
|
Originally posted by: ku_long.hotmail.com
Hey,
I created a hook plug-in which hooks to osgi.framework.extensions.
In the hook plug-in, some classes in a third party jar were refered.
The hook plug-in can be compiled properly but got
java.lang.NoClassDefFoundError exception on some classes in the third
party lib at runtime. If I put the source code of the third party lib
into the plug-in to replace the binary jar file, everything worked fine.
I tried buddy classloading strategy but I still got that problem. I
created a separate plug-in which contains the third party jar file and
exports the third part lib packages. I made the hook plug-in require the
lib plug-in and set buddy policy between the them. But the problem was
still there. Any thought?
Thanks.
|
|
|
|
|
|
|
Re: How can I make osgi find a class in an imported jar [message #330121 is a reply to message #330076] |
Tue, 15 July 2008 14:07   |
Eclipse User |
|
|
|
Originally posted by: ku_long.hotmail.com
>You can include the jar in your hook (if license allows, of course) and
>update your Bundle-ClassPath. Usually it looks like:
>
>Bundle-ClassPath: ., lib/useful.jar
>
>Check out http://wiki.eclipse.org/Plug-in_Development_Environment and
>http://wiki.eclipse.org/Eclipse_Plug-in_Development_FAQ for more information.
>PW
If the "include the jar in your hook" you said means adding the jar file
into the plug-in's classpath on the "Runtime" page of the MANIFEST file
editor,that is what I did. I included the jar (to be more specific, I used
ASM-3.0.jar in the hook plug-in) into my hook plug-in and I can see the
Bundle-ClassPath property contains the jar file. I think the problem is
that my hook class is instantiated in
org.eclipse.osgi.baseadaptor.HookRegistry.java when OSGI is being
configured. That's a very early stage of the startup of eclipse. I believe
at that point, OSGI has not been initiated yet. See the following code in
the HookRegistry, here an instance of my hook class is created:
private void loadConfigurators(ArrayList configurators, ArrayList errors) {
for (Iterator iHooks = configurators.iterator(); iHooks.hasNext();) {
String hookName = (String) iHooks.next();
try {
Class clazz = Class.forName(hookName);
HookConfigurator configurator = (HookConfigurator) clazz.newInstance();
configurator.addHooks(this);
} catch (Throwable t) {
// We expect the follow exeptions may happen; but we need to catch all
here
// ClassNotFoundException
// IllegalAccessException
// InstantiationException
// ClassCastException
errors.add(new
FrameworkLogEntry(FrameworkAdaptor.FRAMEWORK_SYMBOLICNAME,
FrameworkLogEntry.ERROR, 0, "error loading hook: " + hookName, 0, t,
null)); //$NON-NLS-1$
}
}
}
My hook class refers to some classed in ASM-3.0.jar, and a
ClassNoDefException was thrown here. I think at this point, the hook
plug-in has not been initiated and activated yet. The classloader can not
find the class. I oberved in the debug view, the classloader is called
Main$StartupClassLoader.
Thanks.
|
|
|
|
Powered by
FUDForum. Page generated in 0.07250 seconds