[英]Java could not find XML resource bundle
src/java
src/resource/foo/messages.xml
messages_fr.xml
ResourceBundle bundle = ResourceBundle.getBundle("foo.messages", Locale.ENGLISH);
error:错误:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name foo.messages, locale en
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1581)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1396)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:854)
If they are *.properties, no problems.如果它们是 *.properties,则没有问题。
How to load XML resource bundles?如何加载XML个资源包?
By default, Java SE ResourceBundle.getBundle(...)
only understands loading of resource bundles implemented as Java classes or ".properties" files.默认情况下, Java SE
ResourceBundle.getBundle(...)
仅理解作为 Java 类或“.properties”文件实现的资源包的加载。
If you want to load a ResourceBundle
from an XML file, you need to provide a custom ResourceBundle.Control
implementation that implements the resource search and loading strategies.如果要从 XML 文件加载
ResourceBundle
,则需要提供自定义ResourceBundle.Control
实现,以实现资源搜索和加载策略。
There is an example in the ResourceBundle.Control
javadocs ; ResourceBundle.Control
javadocs中有一个示例; look for "Example 2".查找“示例 2”。
I briefly searched for a 3rd-party implementation of an XML ResourceBundle
provider, but I couldn't find anything generic.我简要搜索了 XML
ResourceBundle
提供程序的第 3 方实现,但我找不到任何通用的东西。
(Asking recommendations is off-topic anyway.) (无论如何,询问建议都是题外话。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.