I have a problem implementing this logic in my project. Im using ServiceLoader and I don't know or if it's even possible, but I want to dynamically add JARs to some known directory for app, so the app can load them when it starts. The only thing I achieved was that I know how to create extensible ONE JAR (with META-INF/services), so I can add more and more providers and classes (implementations) to this JAR. The JAR is included to classpath like ordinary library, so app knows about it. What I want to achieve: I don't want to extend one jar file, but I want to extend app by adding more jars like plugins with providers (services), but I don't know how.
Thanks for help!
You just need (a) a URLClassLoader that is constructed with the URLs of all the JAR files in those directories, and (b) call ServiceLoader.load(Class service, ClassLoader loader).