0

I am loading a plug-in dynamically. Both the plug-in and the software have been created by us.

I have an Interface lets call it Foo. There is also FooImpl that just implements that method But FooImpl is in the jar loaded dynamically public interface Foo { void write(..someArgument..) throws Exception; }

I have also a PluginLoader class here is the method

 public
Object loadPlugin(final String jarPath, final Class
pluginInterface) {
    try
    {
        final URI uri = new File(jarPath).toURI();
        final URL url = uri.toURL();

final URLClassLoader ucl = new URLClassLoader(new URL[] { url }); try { final Class<?> pluginClass = Class.forName("FooImpl", true, ucl); // Verify if plugin implements plugin interface. if (pluginClass.getInterfaces()[0].getName().equals(pluginInterface.getName())) { // Instantiate plugin. return pluginClass.newInstance(); } }//[...] </code></pre>

This part is actually working well i think so because after doing some sysout on the pluginClass i notice:
the .getMethods() =
[public void FooImpl.write(..someArgumentType..) throws Exception, public abstract void some.package.Foo.write(..someArgumentType..) throws Exception]

the .getGenericInterfaces() = [interface some.package.Foo]

But when i try to call the method write here is what i get
java.lang.AbstractMethodError: FooImpl.write(..SomeArgumentType..;)V
I dont know why there is a ";" and a "V"

So basically i think that it try to call the interface method instead of the implemented one. So i'm wondering What is going on!

As usual, Thank you for your time and help

4

1 回答 1

0

AbstractMethodError 表明您的代码在运行时尝试使用与最初构建的类不同版本的类。您需要确保在您的执行环境中,类路径上没有您的接口实现的恶意版本。

于 2012-08-17T15:31:56.610 回答