java getBundle 找不到属性文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6360973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:34:16  来源:igfitidea点击:

getBundle can not find properties file

javapropertiesgoogle-checkout

提问by Lumpy

I am trying to use a property file to store my google checkout merchant information. When I call ResourceBundle.getBundle("com_google_checkout_example_settings");

我正在尝试使用属性文件来存储我的 google checkout 商家信息。当我打电话ResourceBundle.getBundle("com_google_checkout_example_settings");

I get the error:

我收到错误:

java.util.MissingResourceException: Can't find bundle for base name com_google_checkout_example_settings, locale en_US

Where do I need to put the properties file so getBundle() can find it? do I need to add the locale to the properties file?

我需要将属性文件放在哪里才能让 getBundle() 找到它?我需要将语言环境添加到属性文件中吗?

回答by plafond

The file needs to be included in your classpath. If it already is being included but is inside a package then you need to provide the full path - ie: ResourceBundle.getBundle("com/google/example/checkout_settings.txt")

该文件需要包含在您的类路径中。如果它已经被包含但在一个包内,那么你需要提供完整的路径 - 即:ResourceBundle.getBundle("com/google/example/checkout_settings.txt")

回答by Jigar Joshi

Where do I need to put the properties file

我需要在哪里放置属性文件

Put into classpath, so that runtime it should be available.

放入类路径,以便运行时它应该可用。

for web app put it in WEB-INF/classes/for jar add it to some package and then

对于 Web 应用程序,将其放入WEB-INF/classes/for jar 中,然后将其添加到某个包中

ResourceBundle.getBundle("some/package/resources.properties");