Dynamic loading of .Jar files
public interface InterfaceClass {
void run();
}
public class CustomPlugin implements InterfaceClass {
@Override
public void run() {
System.out.println("plugin executed");
}
}
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Plugin-Entry>com.plugin.example.CustomPlugin</Plugin-Entry>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
public class Main {
public static void main(String[] args) {
JarPlugin<InterfaceClass> jarPlugin = JarPluginManager.builder(InterfaceClass.class)
.setEntryName("Plugin-Entry")
.setDisabledPluginSuffix(".disabled.jar")
.build();
// Get InterfaceClass from sample.jar
Optional<InterfaceClass> interfaceClassOptional = jarPlugin.loadJar(new File("/home/sample.jar"));
// Get the InterfaceClass list from /home directory
List<InterfaceClass> interfaceClassList = jarPlugin.loadJarDirectory(new File("/home"));
}
}
MIT