I'm running Eclipse and trying to create a simple test program trying our ResourceBundle with a couple of different files. The file is properly named as ResourceFile_us_US.properties. But I'm getting an exception on the getBundle() call because it apparently can't find the file. Where should it be located so it can be found?
You know java is looking for a properties file in a specific locale. You may be baffled why java keeps complaining it can't find a properties file that is right there. A few things to keep in mind when debugging this type of errors:
These resource properties files are loaded by classloader, similar to java classes. So you need to include them in your runtime classpath.
These resources have fully-qualified-resource-name, similar to a fully-qualified-class-name, excerpt you can't import a resource into your java source file. Why? because its name takes the form of a string.
ResourceBundle.getBundle("config")
tells the classloader to load a resource named "config"
with default package (that is, no package). It does NOT mean a resource in the current package that has the referencing class.
ResourceBundle.getBundle("com.cheng.scrap.config")
tells the classloader to load a resource named "config"
with package "com.cheng.scrap."
Its fully-qualified-resource-name is "com.cheng.scrap.config"
More : Can't find bundle for base name com...config, locale zh_CN
Cheers.