Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » ClassNoDefException when an instance of my ClassLoadingHook is created
ClassNoDefException when an instance of my ClassLoadingHook is created [message #114119] Tue, 15 July 2008 18:57 Go to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Hey,

I posted this question to the platform newsgroup and Paul W suggested me
to post it here.

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(to be
more specific, I used ASM-3.0.jar). I imported the ASM-3.0.jar into my
hook plug-in. My hook plug-in can be compiled properly but got
java.lang.NoClassDefFoundError exception on some classes in the ASM jar 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.

After debugging, 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.

Any thought how to solve this problem?

Thanks.
Re: ClassNoDefException when an instance of my ClassLoadingHook is created [message #114829 is a reply to message #114119] Mon, 21 July 2008 13:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Any thought on this issue? Thanks.
Re: ClassNoDefException when an instance of my ClassLoadingHook is created [message #116466 is a reply to message #114119] Sat, 23 August 2008 23:53 Go to previous message
Vinayak is currently offline VinayakFriend
Messages: 5
Registered: July 2009
Junior Member
Raymond wrote:
> Hey,
>
> I posted this question to the platform newsgroup and Paul W suggested me
> to post it here.
>
> 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(to
> be more specific, I used ASM-3.0.jar). I imported the ASM-3.0.jar into
> my hook plug-in. My hook plug-in can be compiled properly but got
> java.lang.NoClassDefFoundError exception on some classes in the ASM jar
> 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.
>
> After debugging, 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.
>
> Any thought how to solve this problem?
>
> Thanks.
>

I hit a similar problem and it turned out to be because in the case of
framework extension bundles (unlike normal bundles) embedded jars can
not be accessed. For them, you need to have the extension bundle
deployed in an "expanded bundle" form. This means 2 things:

1. unpackage the hook jar in a folder inside eclipse/plugins/ naming the
folder with the symbolic name of the extension bundle.

so if your hook jar is hook_x.y.z.jar, you'd end up with

/eclipse/plugins/hook
META-INF/
Manifest.mf
lib/
3rdParty.jar

2. place an eclipse.properties file in the hook folder with the following:
osgi.frameworkClassPath=.,lib/3rdParty.jar

In my case this worked fine. Only thing was it worked only when
launching equinox via the launcher (eclipse.exe) etc.

Vin
Previous Topic:force p2 director to only resolve dependencies on feature level
Next Topic:How do you guys organize tests for plugins ?
Goto Forum:
  


Current Time: Tue Apr 16 19:56:06 GMT 2024

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

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

Back to the top