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?