I have found below styles for developing plugin
1:java.util.ServiceLoader
Working Style:Lookup in META-INF/services and get injected service
Provide Abstract class to other implementor
2:java.net.URLClassLoader
Working Style:Load a required class from a jar file and getinstance .
Provide a interface to other implementor
3: Load from property file
InputStream in =this.getClass().getClassLoader()
.getResourceAsStream("packageName/config.properties");
Working Style 3: Load class name from property file which implements the provided interface
Provide a interface to other implementor
Sample code for 3
public interface PluginInterface {
void performYourOperation();
};
public class PluginImpl implements PluginInterface {
void performYourOperation() {
//perform all operation what plugin is inteneded to do
}
Main Loader:
InputStream in =this.getClass().getClassLoader()
.getResourceAsStream("packageName/config.properties");
configProp.load(in );
String factoryClass = (String) configProp
.get("plugin.factory.class");
Class<?> factory = Class.forName(factoryClass);
PluginInterface factory=(PluginInterface) factory.newInstance();
factoryq.performYourOperation();
};
I have found 3 ways for own plugin implementation style .
Is there any other ways besides above mentioned one .
Is maven and jenkins and other its core level has the same style Or They have some more advance way ? Do any one have good idea for it.
Please dont suggest to use this framework and that , i want to learn and understand the core internal working style.Thank You