Problems loading classes from extending Plugins [message #107960] |
Thu, 07 August 2003 13:50 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Florian Georg![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=Florian.Georg%40innovations.de) Messages: 34 Registered: July 2009 |
Member |
|
|
Hello,
I've got the following problem :
My Plugin "BaseUIPlugin" defines an extension Point "custom.ui.point".
The Plugins "JavaUIPlugin" and "CobolUIPlugin" contribute to that point
(that is, they specify different implementation of some UI-class) and
both depend on "BasePlugin", e.g.:
=======
<extension point="custom.ui.point">
<UI class="my.custom.java.ui.JavaUIClass" />
</extension>
=======
In my "MainPlugin", I lookup all extensions to the extension point in
the PluginRegistry, and try to instantiate the classes.
That isn't that easy, because the classes are located in other Plugins,
which means they are not visible to the ClassLoader of "MainPlugin".
So first,I get the contributing Plugins, take it's classloader and try
to "loadClass (className)"
=======
IExtension[] extensions =
Platform.getPluginRegistry().getExtensionPoint("custom.ui.point ").getExtensions();
//
for (int i = 0; i < extensions.length;i++)
{
String ID =
extensions[i].getDeclaringPluginDescriptor().getUniqueIdenti fier();
Classloader loader =
Platform.getPluginRegistry().getPluginDescriptor(ID).getPlug inClassLoader();
MyUIInterface interface = (MyUIInterface)loader.loadClass
("....").newInstance();
....
}
=======
That seemed works fine, since the ClassLoaders of the
"Java-/CobolUIPlugin" *can* load their classes.
But now I get some strange errors :
After instantiation of the UI-class, my "Main" Plugin seems to be
confused : it can't find e.g. SWT classes anymore and other strange
things....
What happened here ?
Is the above the right way to instantiate classes provided by my
extensions ?
Did I miss something ?
Any help would be greatly appreciated.
greetings
Florian
|
|
|
|
Re: Re: Problems loading classes from extending Plugins [message #108201 is a reply to message #108033] |
Thu, 07 August 2003 16:11 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Florian Georg![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=Florian.Georg%40innovations.de) Messages: 34 Registered: July 2009 |
Member |
|
|
Hello Jeff,
Thanks for your quick help.
I now instantiate my classes via "createExecutableExtension()" correctly.
But the problem remains the same :-(
I think it has something to do with the delegating ClassLoader or
something, because my object looks fine until I try to call some methods
on it :
====
MyObject object = (MyObject) element.createExecutableExtension("class");
// works fine !
object.createUI (composite, some-other-params);
// java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Control
====
The stacktrace shows me no additional information and the debugger steps
into some mysterious DelegatingClassloader, which seems to be unable to
find SWT classes...
Any ideas ?
thanks in advance
Florian
Jeff Hunter wrote:
> Florian Georg wrote:
>
> <snip>
>
>> In my "MainPlugin", I lookup all extensions to the extension point in
>> the PluginRegistry, and try to instantiate the classes.
>> That isn't that easy, because the classes are located in other
>> Plugins, which means they are not visible to the ClassLoader of
>> "MainPlugin".
>>
>> So first,I get the contributing Plugins, take it's classloader and try
>> to "loadClass (className)"
>> =======
>> IExtension[] extensions =
>> Platform.getPluginRegistry().getExtensionPoint("custom.ui.point ").getExtensions();
>>
>> //
>> for (int i = 0; i < extensions.length;i++)
>> {
>> String ID =
>> extensions[i].getDeclaringPluginDescriptor().getUniqueIdenti fier();
>> Classloader loader =
>> Platform.getPluginRegistry().getPluginDescriptor(ID).getPlug inClassLoader();
>>
>>
>> MyUIInterface interface = (MyUIInterface)loader.loadClass
>> ("....").newInstance();
>>
>> ...
>> }
>
>
> After you call IExtensionPoint.getExtensions(), you need to iterate over
> the IExtensions and call getConfigurationElements() for each one. Then
> you can use IConfigurationElement.createExecutableExtension() to
> instantiate the class.
>
> There is a good example of this in the 6/16/03 draft of the Gamma and
> Beck Eclipse book. Look at the bottom of page 55:
>
> http://groups.yahoo.com/group/contributingtoeclipse/files/
>
> Jeff
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04468 seconds