getServiceLoader method
Konstantin Barzilovich
konstantin.barzilovich at oracle.com
Tue Aug 23 14:45:17 UTC 2016
Hello,
Could you please explain, how to use getServiceLoader method of
javax.tools.JavaFileManager interface.
Should location parameter point to location of class or location of
module, which provides implementation?
Is it possible to use this method from unnamed module?
I tried this way:
Path path = Paths.get("/Projects/Test/service.jar");
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH,
Arrays.asList(path));
ServiceLoader<ServiceExample> loader =
fileManager.getServiceLoader(StandardLocation.CLASS_PATH,
ServiceExample.class);
In this example we have service.jar with both service interface
ServiceExample and service implementation ServiceImpl inside.
In addition, we have META-INF/services/package.ServiceExample file, which
contains "package.ServiceImpl".
fileManager is StandardJavaFileManager obtained by getStandardFileManager
method of JavaCompiler.
But this example fails:
java.util.ServiceConfigurationError: package.ServiceExample: use not
declared in module jdk.compiler
--
Thanks,
Konstantin.
More information about the jigsaw-dev
mailing list