Dynamic plugins architecture. Loading jar files from a directory on Spring boot application

1.4k Views Asked by At

I know this question popped up here and there but the posts about this are quite old.
I have a Spring Boot application. I have the need to allow developers develop plugins, implementing an interface and allow my application to load them dynamically on startup.
I don't need discovery on run time, loading at startup is good enough.
I don't want my clients to develop micro services. I want in process modules that will be loaded into the application.
Writing a XML file with plugins to load list is an option although I prefer simple as possible configuration and if this need can be avoided it's better. I have seen some options:

  • OSGi (Very heavy duty for my needs)
  • JPF (Last update on 2007)
  • JSPF (I can't even find a github page for this one).

I really want something quick and easy without a steep learning curve. As mentioned it should play nicely with Spring Boot. What are my options?

1

There are 1 best solutions below

2
Simon Martinelli On

You can use the PropertiesLauncher to add additional paths to your app:

The Main Class must be:

Main-Class: org.springframework.boot.loader.PropertiesLauncher

And then you can start the app:

java -Dloader.path=lib,external-jar.jar -jar my-app.jar

Please read more about that here : https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#executable-jar-launching

and here https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#executable-jar-property-launcher-features