Module system and services directory in META-INF
Cédric Champeau
cedric.champeau at gmail.com
Wed Dec 27 12:22:26 UTC 2017
Hi folks,
Let me rephrase what I think Jochen is saying. It seems there is an
implicit assertion, now, that every file found under META-INF/services are
for the exclusive use of ServiceLoader. It has been brought to the Groovy
language developers attention that Maven had a problem loading Groovy with
JDK 9, because of spurious class not found exception [1]. It turns out that
Maven makes use of java.lang.module.ModuleFinder.of(path).findAll(), which
scans for files under `META-INF/services` and assumes all of them are
service descriptors. This is *not* the case for Groovy, as we have used the
same directory to declare our "extension modules", as well as an additional
file named org.codehaus.groovy.source.Extensions which arguably has nothing
to do under `services` (but, it can be thought as a "service for Groovy").
This is the one responsible for the class not found exception, because this
file contains a single line with the name of a groovy file extension (that
is to say: "groovy") and it tries to load that class (which obviously
doesn't exist).
Now the problem we have is that we cannot move those files easily somewhere
else: this is the adhoc way of registering extension modules in Groovy. So
if we change the directory, all previously published extension modules will
never be found again, unless we scan for both the new and old location,
which has a cost. So there are 2 sides of the coin to this question:
1. is the spec saying somewhere that no-one should ever use
`META-INF/services` for something else than a service for `ServiceLoader`?
If not, then ModuleFinder should probably be patched to recognize that
sometimes it's not the case.
2. the 2d aspect of the question is what Jochen described as "would the
service loader infrastructure let us unload services".
Thanks and best wishes!
[1] http://markmail.org/message/obdyvuv24kqpxm6v
2017-12-27 13:10 GMT+01:00 Remi Forax <forax at univ-mlv.fr>:
> I believe that the doc has been moved to the doc of the ServiceLoader
> https://docs.oracle.com/javase/9/docs/api/java/util/ServiceLoader.html
>
> Rémi
>
> ----- Mail original -----
> > De: "David Holmes" <david.holmes at oracle.com>
> > À: "Jochen Theodorou" <blackdrag at gmx.org>, "jigsaw-dev" <
> jigsaw-dev at openjdk.java.net>
> > Envoyé: Mercredi 27 Décembre 2017 07:27:21
> > Objet: Re: Module system and services directory in META-INF
>
> > On 27/12/2017 5:43 AM, Jochen Theodorou wrote:
> >> On 26.12.2017 19:30, Jochen Theodorou wrote:
> >>> hi all,
> >>>
> >>> Do all files in META-INF/services now have to be well formed according
> >>> to the SPI strucutres in Java, or is it still valid to have other
> >>> files in there as well? Before the module system it was no problem to
> >>> have in there service decriptors, that are services, but do not use
> >>> the ServiceProvider structure. Nothing was disturbed as long as nobody
> >>> tried to load it that way. Now this seems to be different and I am
> >>> wondering where this got specified.
> >>>
> >>> Because the spec does not try to define file layouts so much I have
> >>> the feeling that this is not really specified by the java module
> >>> system. Was it then a decision by some maven plugin writers or maybe
> >>> even the javac guys?
> >>
> >> I found
> >> https://docs.oracle.com/javase/8/docs/technotes/
> guides/jar/jar.html#Service_Provider
> >>
> >> Is there no Java 9 version? Also the spec is not specific enough for
> >> this as it sounds more like implicit assumption than specification
> >
> > https://docs.oracle.com/javase/9/docs/specs/jar/jar.html
> >
> > but the Service provider section is gone. Also the document seems
> > mis-formatted.
> >
> > David
> >
> >> bye Jochen
>
More information about the jigsaw-dev
mailing list