Dynamic loading of modules in Java

后端 未结 2 843
陌清茗
陌清茗 2021-01-06 03:53

In Java, I can dynamically add stuff to classpath and load classes (\"dynamically\" meaning without restarting my application). Is there a known framework/library which deal

2条回答
  •  别那么骄傲
    2021-01-06 04:31

    Perhaps the simplest approach is to load each plugin with it's own class loader. Then discard the class loader and create a new one to reload the plugin. You will want init() and destroy() methods in the plugin API to allow a chance for startup/shutdown type functionality.

    This also has the advantage of isolating the plugins from each other.

    A URLClassLoader is your starting point for this. The general idea is that you provide a XxxPlugin superclass that any plugin subclasses. Consider the example of Applet, which is essentially a GUI plugin (or Midlet, etc).

提交回复
热议问题