ServiceLoader usage in automatic module fails

Alan Bateman Alan.Bateman at oracle.com
Mon Sep 11 10:52:06 UTC 2017



On 11/09/2017 11:03, Christian Stein wrote:
> Hi jigsaw team,
>
> I discovered an issue with the ServiceLoader trying to load services on the
> module-path, when the actual ServiceLoader.load() call resides in an
> automatic module.
>
> I compiled a small demo at [1] and it's console output is visible at [2].
> If you want to re-run the demo, just call "jshell build.jsh" in the root
> directory.
>
> In summary, you have to elevate the automatic module to an explicit one,
> via adding a module-info.class, to get the ServiceLoader load the service
> on the module-path. This can be done with pro's [3] "modulefixer" plugin.
>
> When resorting the class-path and provide a "META-INF/services" file and
> also add the module to the class-path, I can get service loaded ... but
> only within the unnamed module.
Which JAR file contains the service provider? You mentioned "restoring 
the class-path and provide a META-INF/services". Does this mean you 
removed the services configuration file when you had the JAR file on the 
module path as an automatic module?

-Alan


More information about the jigsaw-dev mailing list