2

We're trying to load a class via an Extensionpoint using Eclipse 3. We have defined the extensionPoint in our plugin that only requires a class that implements IScript. IScript is very simple:

public interface IScript {
    void execute(ScriptEngine engine);
}

The package the interface is in is only visible to our plugin where we want to use that extensionpoint. There, we have a class that implements IScript and is provided via the extension.

public class MyScript implements IScript {
    public void execute(ScriptEngine engine) {
        // something
    }
}

This class is completely visible.

The Problem

When we want to get this extension using

IConfigurationElement[] configurationElementsFor = Platform.getExtensionRegistry().getConfigurationElementsFor("my.extensionpoint");
for (IConfigurationElement element : configurationElementsFor) {
    Object obj = element.createExecutableExtension("class");
    IScript script = (IScript) obj;
    }
}

The extension is found and it can load the class (MyScript), but the class cannot be casted to IScript.

After some research, we found out that it's most likely because both plugins (the plugin that has IScript and the one that has MyScript) use different classloaders. We can't, however, find any information about how to fix this. In some other projects, we found the use of

Eclipse-ExtensibleAPI: true

but that doesn't seem to change anything.

How can we force the plugins to use the same classloader?

Chriss
  • 5,157
  • 7
  • 41
  • 75
looper
  • 1,929
  • 23
  • 42
  • Does the plugin containing `MyScript` have the plugin containing `IScript` in its plugin dependencies? Is the package containing `IScript` exported by its plugin? – greg-449 Nov 07 '13 at 13:35
  • @greg-449: Yes, the dependency is there and the IScript is exported. – looper Nov 07 '13 at 13:36
  • Then there should not be a problem, this sort of thing is done all over the place in Eclipse. The plugin dependency should set up the classpath correctly. Perhaps there is some problem in one of the plugin MANIFEST.MF or plugin.xml files. – greg-449 Nov 07 '13 at 13:51
  • @greg-449 at least, eclipse shows no warnings and all settings are defaults. We have other projects where extensionpoints work, too, same looking manifest. – looper Nov 07 '13 at 13:54

0 Answers0