Regarding your first problem, not being able to use static methods in the interface, my suggestion is to simply use the interface with the marker and instantiate it.
The plugin interface can be simply:
public interface Plugin { public void executePlugin(String args[]); }
And then you can do:
if (someClass instanceOf Plugin) { mylist.add(someClass.newInstance()); }
This leads to the second question, how do you get someClass link. There is no standard way to find all classes that implement this interface in your class path , although the approach you can do is to check banks in your class path if this file ends in .class determine its full name through the path in jar and use the Class.forName() method to materialize the class.
In the pseudo code, something like this:
for each jar in your classpath { for each file in JarFile { if (file ends with .class) { materialize class using Class.forName } } }
With an instance of Class you can check if it implements your Plugin interface.
Also keep in mind that if you need to add some context to your plugins, you can create a constructor in every plugin that gets your context object, instead of having a default constructor. In this case, instead of using newInstance() you will need to get a constructor with the arguments that you would like using reflection.
source share