Skip to content

cmeza20/java-jar-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Jar Plugin Maven Central

Dynamic loading of .Jar files

Wiki

Home


Manager


Logger

Example

InterfaceClass.java
public interface InterfaceClass {
    void run();
}
Another Jar project (sample.jar)
public class CustomPlugin implements InterfaceClass {
    @Override
    public void run() {
        System.out.println("plugin executed");
    }
}
Another Jar project (pom.xml)
Set EntryName into MANIFEST
<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>
JarPlugin initialized
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"));
    }
}

License

MIT

About

Dynamic loading of .Jar files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages