Results 1 to 1 of 1
- 11-03-2010, 03:16 PM #1Member
- Join Date
- Nov 2010
- Rep Power
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
- By coyler_21 in forum NetBeansReplies: 5Last Post: 10-27-2010, 10:04 AM
- By AndreB in forum Advanced JavaReplies: 3Last Post: 02-08-2010, 02:55 PM
- By dark_cybernetics in forum New To JavaReplies: 0Last Post: 08-19-2008, 05:44 PM
- By sajut in forum New To JavaReplies: 0Last Post: 02-15-2008, 06:47 AM