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. 替換動態加載的罐子
- 4. WILDFLY - 加載動態罐子拋出java.lang.ClassNotFoundException
- 5. Java ClassLoader - 將動態加載的罐子添加到系統類加載器
- 6. 如何嘲笑的動態加載的罐子方法
- 7. 從單罐內加載靜態資源
- 8. 從動態加載的罐子中使用主jar方法
- 9. Tomcat上的AbstractMethodError setBinaryStream
- 10. AbstractMethodError上org.apache.xalan.processor.TransformerFactoryImpl
- 11. AbstractMethodError上Node.getTextContent()
- 12. URLClassloader無法從動態加載罐子類
- 13. 從遠程位置動態加載罐子
- 14. 從URL加載罐
- 15. 添加圖像罐子動態
- 16. 啓動屏幕加載罐子
- 17. 錯誤加載的罐子
- 18. AbstractMethodError上調用Exception.printStackTrace
- 19. 動態加載MainFrame上的圖標
- 20. 如何動態加載NSWindow上的NSView?
- 21. Windows 7上的動態加載失敗
- 22. 加載資源在罐
- 23. WinRun4J - 無法加載庫罐
- 24. 如何在Flash中反動態加載動態加載的PNG
- 25. 動態地控制@Formula列的惰性加載/動態加載
- 26. 在Silverlight上動態加載圖像
- 27. 如何在android上動態加載imagebuttons?
- 28. 在ios上動態加載libspotify
- 29. AppEngine上動態加載BlobProperty圖像
- 30. 動態加載靜態庫?
你是通過實例調用寫入方法,即'((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