Search code examples
javaclassloader

Is it possible to load JAR to your running Java application on the fly?


I have plugin system in my Java application. Is it possible to load JAR / Java classes on the fly to your application, or do I have to include these JAR / Java classes to my application?

My idea was to load plugin to application and then call interface method of this class, without need to restart Java application. Is this possible or even wise at all?


Solution

  • I'd recommend to use OSGi for dynamic plugin loading / unloading. It handles all the class loading stuff. If you cannot use OSGi, you'll have to use own class loaders and configure them with the location of your to-be-loaded jar files.