What is the optimal way to get all files in META-INF/services/ in automatic module

PavelTurk pavelturk2000 at gmail.com
Mon Dec 23 09:12:46 UTC 2024


Hello everyone,

I have `Module module`. If this module is automatic I need to get the list of all its services/providers, so,
as I understand the only way to do it is to read its META-INF/services folder. I tried:

if (module.getDescriptor().isAutomatic()) {
     ClassLoader classLoader = module.getClassLoader();
     Enumeration<URL> resources = classLoader.getResources("META-INF/services/");
     while (resources.hasMoreElements()) {
             URL resource = resources.nextElement();
             ...
     }
}

but it doesn't work. All `resource`s have same path ending in `....META-INF/service`.
I tried:

     ModuleReference reference = ... ;
     var entries = reference.open().list().collect(Collectors.toList());

It worked, but I need only one folder, but not all with all classes etc. Could anyone what is the optimal way to do it?

Best regards, Pavel


More information about the jigsaw-dev mailing list