java - URLClassLoader keeps throwing ClassNotFoundException. What am I doing wrong? -
java - URLClassLoader keeps throwing ClassNotFoundException. What am I doing wrong? -
i'm working on university java project requires me implement simple plugin architecture. main application in project have load plugins specified directory located in project b. after having done research on topic (including stackoverflow), decided go urlclassloader load classes might instatiate. project b references project , plugins extend mutual plugin class (might interface should not create difference). have got far:
the source plugin class seek load:
package plugin; import de.uks.student.pluginpattern.model.editorplugin; public class circle extends editorplugin { @override public void init() { } }
and code supposed load class:
public void init(string[] args) { editorpane = new editorpane().withwidth(500).withheight(500); toolbar = new toolbar(); plugins = new editorpluginset(); // load plugins file plugindir = new file(plugin_path); if (!plugindir.exists()) { system.err.println("plugin path not found!!"); return; } string[] plugins = plugindir.list(); if (plugins == null) { system.err.println("plugin path points file!!"); return; } (string pluginstring : plugins) { (string argstring : args) { if (pluginstring.contains(argstring)) { system.out.println("loading plugin " + pluginstring); file pluginfile = new file(plugin_path + "/"); // getabsolutepath embeds relative path ... /../pluginproject ... // may not processed correctly os (windows @ least), // right path manually (just on safe side) string absolutepath = pluginfile.getabsolutepath(); string[] split = absolutepath.split("\\\\"); list<string> splitsimplelist = arrays.aslist(split); arraylist<string> splitlist = new arraylist<>(splitsimplelist); (int = 0; < splitlist.size() - 1; ++i) { if (splitlist.get(i + 1).equals("..")) { splitlist.remove(i); splitlist.remove(i); break; } } stringbuilder b = new stringbuilder(); (string string : splitlist) { b.append(string); b.append("/"); } file pluginfileforrealthistime = new file(b.tostring()); url pluginurl = null; seek { pluginurl = pluginfileforrealthistime.touri().tourl(); } grab (malformedurlexception e) { // todo auto-generated grab block e.printstacktrace(); } url[] urls = {pluginurl}; classloader parentclassloader = this.getclass().getclassloader(); urlclassloader uloader = new urlclassloader(urls, parentclassloader); class<?> pluginclass = null; seek { string classname = "plugin." + argstring; pluginclass = uloader.loadclass(classname); } grab (classnotfoundexception e) { // todo auto-generated grab block e.printstacktrace(); } } } } }
now end classnotfoundexception:
java.lang.classnotfoundexception: plugin.circle @ java.net.urlclassloader$1.run(unknown source) @ java.net.urlclassloader$1.run(unknown source) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ java.lang.classloader.loadclass(unknown source) @ de.uks.student.pluginpattern.model.editorsystem.init(editorsystem.java:412) @ de.uks.student.pluginpattern.editorsystem.main(editorsystem.java:13)
i've checked that
the generated url can correctly resolved web browser , windows explorer. circle.class has been built , nowadays in directory referenced used url classname resolves "plugin.circle" should right binary name use removing inheritance plugin.circle not create difference.i've pretty much run out of ideas on else try. doing wrong?
i had point classloader bin folder instead of bin/plugins folder
java classloader classnotfoundexception urlclassloader
Comments
Post a Comment