4

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");

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?

Lumpy
  • 3,632
  • 4
  • 34
  • 58

2 Answers2

5

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")

plafond
  • 101
  • 2
  • Part of the problem with some development setups is that they do not warn when .properties files are placed as siblings of the com package folder, and the IDE automatically adds '.' to the classpath. – memnoch_proxy Jul 20 '13 at 00:02
2

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

ResourceBundle.getBundle("some/package/resources.properties");
jmj
  • 237,923
  • 42
  • 401
  • 438
  • So why is that you showing full name of file with locale (but not in case above) and extension "resource". But in other examples, which of course not working, there is no such obligation? Example http://stackoverflow.com/a/20527227/929209 and http://www.avajava.com/tutorials/lessons/how-do-i-read-a-properties-file-with-a-resource-bundle.html – Dawid D Feb 20 '17 at 20:50