Modular Design

Discussion in 'Spigot Plugin Development' started by Arjan, Nov 29, 2015.

  1. Hi,

    Is there a possibility to create plugins using a modular design? This way I can create multiple jars that will be 'combined/imported' in the main jar when the server starts. This means that I can also load and unload the modules separately and applying updates to individual modules without having to restart the server.

    -Arjan
     
  2. yes
     
  3. I would not recommend dynamically controlling jar files but whatever. You need to use a classloader to do this.

    Code (Text):
    File file = new File("path/to/newjar.jar");
    ClassLoader cl  = new URLClassLoader(new URL[]{file.toURL()};);

    Class clazz = cl.loadClass("com.package.main");
     
    • Agree Agree x 1
  4. Maybe you should use the API method. In the first and main Jar, make an API for anything you need. All modules then use the API to do what they need to do. Or you could reverse that, where the main tries all other APIs. I prefer the first.