Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Eclipse class loader
Eclipse class loader [message #266535] Wed, 11 August 2004 14:27 Go to next message
Eclipse UserFriend
Originally posted by: mail.helmut-quathamer.de

I am writing a plug-in (A) which is depending on another plug-in (B). The
other plug-in (B) only contains third party libraries.

My problem now is, the third party library uses Class.forName(String) for
creating new objects - especially from the plug-in (A). Since there are
two class loaders - for each plug-in one - Class.forName(String) from
plug-in (B) cannot find the specified class from the plug-in (A).

In the old times without eclipse plug-in technology, there was only one
application class loader which had access to all the classes, it was no
problem to create a new instance.

Any idea how to solve this problem? By the way, I don't want to include the
third party libraries in my plug-in (A) because there will be more plug-ins
in the future, which will be depending on both plug-ins (A) and (B).

Thanks,

Helmut
Re: Eclipse class loader [message #266557 is a reply to message #266535] Wed, 11 August 2004 15:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mylastname.mycompany.com

On Wed, 11 Aug 2004 18:27:52 +0000, Helmut Quathamer wrote:

> I am writing a plug-in (A) which is depending on another plug-in (B). The
> other plug-in (B) only contains third party libraries.
>
> My problem now is, the third party library uses Class.forName(String) for
> creating new objects - especially from the plug-in (A). Since there are
> two class loaders - for each plug-in one - Class.forName(String) from
> plug-in (B) cannot find the specified class from the plug-in (A).
>

Get the classloader of a class in B, and ask it to load the class you
want. Since eclipse creates a classloader heirarchy between plugins that
depend on each other, your ClassLoader.loadClass() will end up getting
delegated to the parent of classloader B, which will be classloader A.

Matt
Re: Eclipse class loader [message #303040 is a reply to message #266535] Sat, 06 May 2006 11:02 Go to previous message
Eclipse UserFriend
These kind of problems can be solved with eclipse buddy classloading.

The basic structure of eclipse uses the OSGi framework, declared in the
MANIFEST.MF file.

For any given plugin, the MANIFEST.MF specifies:
Bundle-ClassPath: the internal plugin classpath
Require-Bundle: any plugins that this plugin depends on
Export-Package: classes in this plugin that should be exported

So left to it's own devices, a plugin classloader can see any classes on
the Bundle-ClassPath + any classes that other plugins in the
Require-Bundle header have exported using Export-Package.

This becomes problemmatic when your have a common plugin, A, that
provides some kind of service or factory. A needs to instantiate
classes "plugged in" at runtime from plugins it was not aware of.

You can set the Eclipse-BuddyPolicy: header in plugin A, and then set
the Eclipse-RegisterBuddy: header in the implementor plugins. Info on
these headers is in the help, but basically it allows the implementor
Export-Package classes to be visible to plugin A, the factory plugin.

Later,
PW
Previous Topic:Headless application and java.lang.NoClassDefFoundError exception
Next Topic:Where is Open Type in 3.1.2 on OSX?
Goto Forum:
  


Current Time: Wed May 07 17:48:59 EDT 2025

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

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

Back to the top