I am loading a plug-in dynamically. Both the plug-in and the software have been created by us.动态加载罐上的AbstractMethodError
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
0
A
回答
0
AbstractMethodError表明您的代码正在试图在运行时使用不同版本的类,而不是它最初构建的类。您需要确保在执行环境中,类路径中没有流行的接口实现版本。
相关问题
- 1. 替换动态加载的罐子
- 2. 如何嘲笑的动态加载的罐子方法
- 3. 从动态加载的罐子中使用主jar方法
- 4. AbstractMethodError上org.apache.xalan.processor.TransformerFactoryImpl
- 5. 从远程位置动态加载罐子
- 6. URLClassloader无法从动态加载罐子类
- 7. 添加图像罐子动态
- 8. 错误加载的罐子
- 9. 如何动态加载NSWindow上的NSView?
- 10. Windows 7上的动态加载失败
- 11. WinRun4J - 无法加载库罐
- 12. 加载资源在罐
- 13. 动态地控制@Formula列的惰性加载/动态加载
- 14. 如何在Flash中反动态加载动态加载的PNG
- 15. 在ios上动态加载libspotify
- 16. 如何在android上动态加载imagebuttons?
- 17. 在Silverlight上动态加载图像
- 18. 动态加载静态库?
- 19. 动态加载jquery
- 20. 动态加载NIB?
- 21. 动态加载DLL
- 22. .net动态加载
- 23. 动态加载mlmodel
- 24. 动态加载CSS
- 25. 动态加载ListView
- 26. 动态加载DLL
- 27. 加载库动态
- 28. 动态加载JWplayer
- 29. 动态加载jquery
- 30. 动态加载assemly
你是通过实例调用写入方法,即'((Foo)instance).write(??)'还是通过反射? – MadProgrammer 2012-08-17 14:59:13
final PluginLoader loader = new PluginLoader(); final Object loadedLayer = loader.loadPlugin(pathToPlugin,Foo.class); this.plugin =(Foo)loadedLayer;我真的很抱歉,我没有使用stackoverFlow – drgn 2012-08-17 15:04:39
如果(pluginClass instanceof pluginInterface)) - 不应该这是你的接口检查? – JamesB 2012-08-17 15:53:48