From gunnar at hibernate.org Tue Aug 31 08:24:22 2021 From: gunnar at hibernate.org (Gunnar Morling) Date: Tue, 31 Aug 2021 10:24:22 +0200 Subject: Portable retrieval of resource bundles across module path and class path In-Reply-To: References: <27fc0411-54de-879b-a1d3-d32e3a1c06c5@oracle.com> <4f14fc9b-fca1-f6cb-d536-e2456a0a2dad@oracle.com> Message-ID: Hi all, I've written a quick blog post about my experiences with ResourceBundleProvider et al.: https://www.morling.dev/blog/resource-bundle-lookups-in-modular-java-applications/ The scenario I'm describing is that of a "well-structured monolith", with each module contributing its own resource bundle(s). It took a while to set things up in a way working with Java 9+ (with module and with classpath) and Java 8, but I've found my ways in the end. Thanks again for all the feedback and input you provided! Best, --Gunnar Am Fr., 23. Juli 2021 um 21:14 Uhr schrieb Mandy Chung < mandy.chung at oracle.com>: > > > On 7/23/21 4:17 AM, Gunnar Morling wrote: > > Thanks a lot for your replies, Mandy and Alan! > > > I assume the class path is running on JDK <= 8, right? Otherwise > > Is there something missing after "Otherwise"? > > > It was a typo (I should have taken it out). > > In fact, I'm looking for a way to run this > > - Java 1.8 on classpath > - Java 9+ on classpath > - Java 9+ on module path > > As I've learned by now, ResourceBundleControlProvider implementations on > Java 1.8 will only be loaded via the extension mechanism, which often is > impractical to use. So it seems I'll need to amend my solution described > above to pass in the custom Control explicitly to > ResourceBundle.getBundle(). I could use the ResourceBundleControlProvider > in a MR JAR, but there seems not much of an advantage to doing that. > > > 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. > > > Right, this is indeed the simplest approach if the JAR file contain > resource bundles in .properties format and no .class files in that > package. i.e. you can keep the resource bundles in `dev/morling/greeter` > and deploy them 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. > > > It's common to have the resources packaged in separate JARs from the code > and also an application includes all resources. This educational purpose > demo shows an advanced feature. > > > > 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: > > java.lang.LayerInstantiationException: Package dev.morling.greeter.fr > > in both module dev.morling.greeter.german and module > dev.morling.greeter.french > > > this looks a little suspicious. GreetingMessages_de.properties should be > expected in dev.morling.greeter. > > Mandy > From sormuras at gmail.com Tue Aug 31 08:32:19 2021 From: sormuras at gmail.com (Christian Stein) Date: Tue, 31 Aug 2021 10:32:19 +0200 Subject: Portable retrieval of resource bundles across module path and class path In-Reply-To: References: <27fc0411-54de-879b-a1d3-d32e3a1c06c5@oracle.com> <4f14fc9b-fca1-f6cb-d536-e2456a0a2dad@oracle.com> Message-ID: Hi Gunnar, I skimmed your post briefly and will read it in detail later -- though I wonder whether my over 4 years old SO question is answered as a side-effect by your findings. https://stackoverflow.com/questions/44167502/how-to-configure-resourcebundle-no-fallback-control-in-java-9 Cheers, Christian On Tue, Aug 31, 2021 at 10:25 AM Gunnar Morling wrote: > Hi all, > > I've written a quick blog post about my experiences with > ResourceBundleProvider et al.: > > > > https://www.morling.dev/blog/resource-bundle-lookups-in-modular-java-applications/ > > The scenario I'm describing is that of a "well-structured monolith", with > each module contributing its own resource bundle(s). It took a while to set > things up in a way working with Java 9+ (with module and with classpath) > and Java 8, but I've found my ways in the end. > > Thanks again for all the feedback and input you provided! > > Best, > > --Gunnar > > > > Am Fr., 23. Juli 2021 um 21:14 Uhr schrieb Mandy Chung < > mandy.chung at oracle.com>: > > > > > > > On 7/23/21 4:17 AM, Gunnar Morling wrote: > > > > Thanks a lot for your replies, Mandy and Alan! > > > > > I assume the class path is running on JDK <= 8, right? Otherwise > > > > Is there something missing after "Otherwise"? > > > > > > It was a typo (I should have taken it out). > > > > In fact, I'm looking for a way to run this > > > > - Java 1.8 on classpath > > - Java 9+ on classpath > > - Java 9+ on module path > > > > As I've learned by now, ResourceBundleControlProvider implementations on > > Java 1.8 will only be loaded via the extension mechanism, which often is > > impractical to use. So it seems I'll need to amend my solution described > > above to pass in the custom Control explicitly to > > ResourceBundle.getBundle(). I could use the ResourceBundleControlProvider > > in a MR JAR, but there seems not much of an advantage to doing that. > > > > > 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. > > > > > > Right, this is indeed the simplest approach if the JAR file contain > > resource bundles in .properties format and no .class files in that > > package. i.e. you can keep the resource bundles in `dev/morling/greeter` > > and deploy them 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. > > > > > > It's common to have the resources packaged in separate JARs from the code > > and also an application includes all resources. This educational > purpose > > demo shows an advanced feature. > > > > > > > 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: > > > > java.lang.LayerInstantiationException: Package > dev.morling.greeter.fr > > < > https://urldefense.com/v3/__http://dev.morling.greeter.fr__;!!ACWV5N9M2RV99hQ!fILkGEkNjEpD7sQnRSKHS3M4qZY3lXvfXij2Q4XgaGa9P1mVdmrAFrdcvVKsPREq3A$ > > > > in both module dev.morling.greeter.german and module > > dev.morling.greeter.french > > > > > > this looks a little suspicious. GreetingMessages_de.properties should > be > > expected in dev.morling.greeter. > > > > Mandy > > >