Portable retrieval of resource bundles across module path and class path

Gunnar Morling gunnar at hibernate.org
Thu Jul 22 19:23:45 UTC 2021


Hi all,

I'm trying to figure out how a modular application should handle
cross-module resource bundle look-ups, supporting running on both the
module path and the class path. At a first look, resource bundle semantics
in the two modes are at odds with each other:

* When running on the classpath, all modules (or JARs, I should say) would
have to provide their bundles in one and the same package, so
ResourceBundle.getBundle() will pick them  all up
* When running on the module path, this would lead to split package issues,
so each module has to use a distinct package and a ResourceBundleProvider
which exposes the module's bundles

So what I ended up doing is using the distinct package approach with RBP to
make things work when running on the module path. When running on the class
path, I'm using a ResourceBundleControlProvider whose returned Control
adjusts bundle names to match the package naming pattern used in the
different modules.

Is this the recommended approach for solving the issue of making resource
bundles in a modular application functional on module and class path? Or is
there a simpler approach to achieve the same?

Thanks a lot,

--Gunnar


More information about the jigsaw-dev mailing list