我已经搜索过,但没有结果。运行 JSF 应用程序时,我在控制台中收到此错误。
我正在尝试按照教程将基本的 messages.properties 文件添加到我的计算器应用程序中。该教程说“如果您使用 Eclipse Java EE,请务必添加 resources/messages.properties 作为源文件夹。”
这是在应用程序的构建路径中吗?因为我已经尝试过了,但行不通。
我的属性文件的文件路径:ProjectName/WebContent/resources/messages.properties
如何在 faces-config.xml 中引用属性文件:
<application>
<message-bundle>/JavaServerFaces/WebContent/resources/messages</message-bundle>
</application>
我的 faces-config.xml 的文件路径:ProjectName/WebContent/WEB-INF/faces-config.xml
最佳答案
捆绑文件必须最终位于类路径中,并且需要被标识为类路径资源,而不是本地磁盘文件系统路径或 Web 资源。
- 创建包
resources
与您为 Java 代码创建包的位置和方式相同。 - 删除
messages.properties
文件放在那里。 - 将其引用为
<message-bundle>resources.messages</message-bundle>
.
关于java.util.MissingResourceException : Can't find resource for bundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17108964/