Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How can I make osgi find a class in an imported jar
How can I make osgi find a class in an imported jar [message #329755] Wed, 02 July 2008 20:20 Go to next message
Eclipse UserFriend
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 #329826 is a reply to message #329755] Mon, 07 July 2008 13:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Can anyone help me on this issue? Thanks.
Re: How can I make osgi find a class in an imported jar [message #329871 is a reply to message #329755] Tue, 08 July 2008 21:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

After investigation on this issue, it seemed the classes in the third
party jar file are loaded when the
org.eclipse.osgi.baseadaptor.HookRegistry tries to register my hook. This
happened in the very early stage during the start up of eclipse. At that
time, the osgi frame could not regonize those classes yet.
Is there any property I can set to make osgi can recognize them? Thanks.
Re: How can I make osgi find a class in an imported jar [message #329933 is a reply to message #329755] Thu, 10 July 2008 19:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ku_long.hotmail.com

Can anyone take a look at my question? or if this question is not supposed
to be posted to this news group, please direct me to the right place.
Thanks.
Re: How can I make osgi find a class in an imported jar [message #330076 is a reply to message #329755] Mon, 14 July 2008 14:15 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


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 18:07 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: How can I make osgi find a class in an imported jar [message #330125 is a reply to message #330121] Tue, 15 July 2008 18:35 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Hmmm, if http://wiki.eclipse.org/Adaptor_Hooks doesn't help you might
need to ask this on the eclipse.technology.equinox newsgroup.

I would think that an adaptor hook would be a valid bundle (and so would
load as expected) but maybe it follows different rules if (as you
mentioned) the framework isn't fully operational yet.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:Why is the Debug view named so?
Next Topic:Re: Command FrameWork- loosing popup menus when I detach window
Goto Forum:
  


Current Time: Sat Nov 02 16:50:50 GMT 2024

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

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

Back to the top