If I want to make my Java program to be able accept plugins, how can I make Java plugins to use classes of core program without including all the code to the plugin code? How plugin can have access to programs interface without including it to it's own jar file?
A:
Use java.net.URLClassLoader.newInstance
with your application's class loader as the parent.
Tom Hawtin - tackline
2010-03-03 07:56:40
What if I use reflection to find out if plugin has certain methdo names and class names ? And then call those methods from main program ?
newbie
2010-03-03 08:03:42
@newbie, that's the general idea, yes. That way, you don't have to know exactly what class(es) you'll be dealing with at compile time. The programmer of a plugin just has to ensure that they conform to the interfaces your application expects.
Mike Daniels
2010-03-03 08:09:17
@newbie @Mike No need for that. You can simply implement an interface/extend a class from the application code.
Tom Hawtin - tackline
2010-03-05 16:01:45
+4
A:
Have a look at the Java Plugin Framework. It uses the concept of extension points or places in your application that are designed to be extended. Plugins are the means that your application is then extended.
objects
2010-03-03 08:00:56