Pavel_K Pavel_K - 5 months ago 33
Java Question

How to get ResourceBundle from another Module in Java 9?

I have two modules: module-a and module-b. Module-a has properties file (

). Module-a exports
package. In module-b I want to get this resource. For this I do the following in module-b:

Module moduleA = ClassFromModuleA.class.getModule();
ResourceBundle resourceBundle = ResourceBundle.getBundle("com/foo/texts",
Locale.ENGLISH, moduleA.getClassLoader());
System.out.println("TEST :" + resourceBundle.getString(key);

This is what I get:

Caused by: java.util.MissingResourceException: Can't find bundle for base name com/foo/texts, locale en
at java.base/java.util.ResourceBundle.throwMissingResourceException(
at java.base/java.util.ResourceBundle.getBundleImpl(
at java.base/java.util.ResourceBundle.getBundleImpl(
at java.base/java.util.ResourceBundle.getBundle(

What is my mistake?

Answer Source

The "Resource Bundles in Named Modules" section of ResourceBundle provides the details on how resources in named modules are located.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download