Portable retrieval of resource bundles across module path and class path
Gunnar Morling
gunnar at hibernate.org
Fri Jul 23 15:58:18 UTC 2021
Am Fr., 23. Juli 2021 um 15:05 Uhr schrieb Alan Bateman <
Alan.Bateman at oracle.com>:
> On 23/07/2021 12:17, Gunnar Morling wrote:
> > :
> >
> > > For the migration scenario where the resources are in .properties
> > format then the simplest may be to just deploy the JAR files on the
> > module path where they will be treated as automatic modules.
> >
> > In the scenario I have in mind (for educational purposes mainly) the
> > JAR files contain the properties file as well code and should be
> > usable as "proper" (i.e. non-automatic) modules as well as on the
> > classpath.
> >
> > > There are no split package issues unless the resources have been
> > compiled as .class files.
> >
> > That's very interesting, it's not what I observe. Having the
> > *.properties in one and the same package in multiple modules triggers
> > an error upon start-up:
>
> I should have been clearer that the "no split package issues" comment
> was in the context of automatic modules where you "move" an existing JAR
> file containing .properties files from the class path to the module
> path. The .class files in the JAR file are used to determine the set of
> packages in the automatic module so if there are no .class files then it
> doesn't have any packages.
>
> That said, I'm surprised by the exception message as suggests there must
> be dev.morling.greeter.fr classes or resources in the
> dev.morling.greeter.german module. I think I'd need to see the output of
> `jar --file=<jar> --describe-module` to be sure.
>
Yes, there is such resource which I had created for demo purposes (see the
jar -tf output above):
dev/morling/greeter/fr/GreetingMessages_de.properties
Here's the output you requested:
jar --describe-module --file
german/target/resourceloading-test-german-1.0-SNAPSHOT.jar
dev.morling.greeter.german at 1.0-SNAPSHOT
jar:file:///.../resource-loading-test/german/target/resourceloading-test-german-1.0-SNAPSHOT.jar!/module-info.class
requires dev.morling.greeter.base
requires java.base mandated
provides dev.morling.greeter.spi.GreetingMessagesProvider with
dev.morling.greeter.de.internal.GermanGreetingMessagesProvider
contains dev.morling.greeter.de.internal
Interestingly, the dev.morling.greeter.fr package of the
GreetingMessages_de.properties resource file isn't listed there, but it
does trigger the split package error later on. Based on what you say, I
take it that split package error *is* expected in this situation, it'
surprising though to not see the package listed in the output of
--describe-module.
If you wanted to reproduce this yourself, the code is here:
https://github.com/gunnarmorling/resource-bundle-test/tree/split-package
Just run "mvn clean install" on JDK 9+, then "mvn exec:exec -pl
:resourceloading-test-runner" for running the application, which should
fail.
Thanks,
--Gunnar
> -Alan
>
More information about the jigsaw-dev
mailing list