Loading service implementations with ServiceLoader from external JARs
I'm having a problem making the ServiceLoader mechanism to work for me. I found a few articles:
Using the ServiceLoader API to build a modular applications
Writing a Generic Service Loader: How to Take advantage of Java's Flexibility and Power
With this help, I managed to create a project that has META-INF/services folder with files named after my interfaces, listing implemented services (classes) each. This works fine. Now, I have no clue how to make it work from external JAR - so just putting the JAR in the propper directory would make the service available in my program.
As I understand it, all I have to do is put those external "plugins" in one JAR, put the folder META-INF/services in that JAR as well, with all the listing as before. BUT where do I put the JAR so the ServiceLoader finds it?
I suppose I have to include the path to the prime JAR (app) - classpath, probably? But as far as I know, classpath doesn't do much good for JARs - you have to list them all to be loaded.
So, the questions are:
What path do I have to set and where for the external JAR to be found and loaded by the ServiceLoader mechanism? Can the java packages defined inside the external JAR (plugin) break this? (for example, do I have to put the implemented services to the same package as the interface?)
Thanks a lot