Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.MissingResourceException

I am getting below exception while running an application. This application read abc.properties file,

Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name abc, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:853)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:822)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:566)
    at com.ibm.dst.DailyExtract.getResourceBundle(DailyExtract.java:104)
    at com.ibm.dst.DailyExtract.main(DailyExtract.java:131)

abc.properties file reside at the workspace. I am using RSA7 as IDE, is there any setting problem? any suggestions are welcome.....

Thanks a lot in advance

like image 825
user306689 Avatar asked Apr 14 '10 10:04

user306689


4 Answers

Follow the hints in this post and see if you made one of those mistakes, which could be (copy pasted from the link):

  1. These resource properties files are loaded by classloader, similar to java classes. So you need to include them in your runtime classpath.

  2. 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.

  3. 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.

  4. 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"

like image 150
Alberto Zaccagni Avatar answered Oct 19 '22 23:10

Alberto Zaccagni


You just need to add the package name while getting the file

For example if your properties name is "ABC.properties" in package a.b.c then the below code will work perfectly

ResourceBundle labels = ResourceBundle.getBundle("a.b.c.ABC");
like image 32
Heggi Avatar answered Oct 20 '22 00:10

Heggi


Just copy the resource file over to where your class files are.

In my case my directory was:

bin 
  - com 
     - brookf 
        - all my packages here. 

copy your resource file to the bin folder.

like image 43
MesamH Avatar answered Oct 20 '22 00:10

MesamH


Loading the Properties file for localization stuff is also affected by the package naming. If you put your Properties file in a package like org.example.com.foobar and load it just by its name abc you have to add the prefix org.example.com.foobar, too. If you have the properties at a different location (like in the root directory or in another subdir) you have to change either the name to load or the classpath.

I run fine in placing the properties file in the same location where the .java file is and using something like

private static ResourceBundle RES = ResourceBundle.getBundle(NameOfTheCurrentClass.class.getCanonicalName());
like image 34
Progman Avatar answered Oct 20 '22 01:10

Progman