我有两个模块:module-a 和 module-b。模块-a 具有属性文件 ( com/foo/texts_en.properties
)。模块 - 一个导出com.foo
包。在 module-b 中,我想获取此资源。为此,我在 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);
这就是我得到的:
Caused by: java.util.MissingResourceException: Can't find bundle for base name com/foo/texts, locale en
at java.base/java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:2045)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1679)
at java.base/java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1572)
at java.base/java.util.ResourceBundle.getBundle(ResourceBundle.java:1273)
我的错误是什么?