i'm creating complex (well me anyway haha) program in java , require simple/easy use plugin framework. stumbled across jspf, watched video , though great! takes less 5 minutes implement.
reading doc have created plugin interface extends plugin jspf. made simple "hello world" method. created test plugin class.
package main.plugin.impl; import main.plugin.plugin; import net.xeoh.plugins.base.annotations.pluginimplementation; /** * created adam on 08/05/15. */ @pluginimplementation public class testplugin implements plugin { @override public void helloworld() { system.out.println("hello world"); } }
the final step load plugin. here's main class.
package main; import main.plugin.plugin; import net.xeoh.plugins.base.pluginmanager; import net.xeoh.plugins.base.impl.pluginmanagerfactory; import java.io.file; /** * created adam on 08/05/15. */ public class main { public static void main(string[] args) { pluginmanager pm = pluginmanagerfactory.createpluginmanager(); pm.addpluginsfrom(new file("src/").touri()); plugin p = pm.getplugin(plugin.class); p.helloworld(); } }
according examples on jspf google code page, that's need do, , running.
however getting nullpointerexception on p.helloworld(); line.
i can see plugin isn't getting loaded, don't know how resolve issue. appreciated. thanks
edit : i've had success. if use
pm.addpluginsfrom(new uri("classpath://*"));
it picks plugins , loads them. if use new file method , type exact path of class file, won't load. ideas?
edit 2 : figured out, had paths wrong. working fine now.
Comments
Post a Comment