Thursday April 06, 2006
Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)
(Here is another blog on how to debug this exception, but here is what I will do.)
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:
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"For instance, you have a project like
C:\ws\netbeans5\scrap>
| build.xml
+---build
| \---classes
| \---com
| \---cheng
| \---scrap
| Scrap.class
|
+---src
| \---com
| \---cheng
| \---scrap
| config.properties
| Scrap.java
For this statement in Scrap.java: ResourceBundle config = ResourceBundle.getBundle("config"); to work, you will need to
cp src\com\cheng\scrap\config.properties build\classes\
such that config.properties is directly under classes, and at the same level as com. Alternatively, you can put config.properties into a config.jar such that config.properties is at the root of config.jar without any subdirectories, and include config.jar in the classpath.
For this statement in Scrap.java: ResourceBundle config = ResourceBundle.getBundle("com.cheng.scrap.config"); to work, you will need to
cp src\com\cheng\scrap\config.properties build\classes\com\cheng\scrap\
such that config.properties is directly under classes\com\cheng\scrap\, and at the same level as scrap. Alternatively, you can put com\cheng\scrap\config.properties (along with the long subdirectories) into a config.jar, and include config.jar in the classpath.
You may be wondering why it is made so confusing? The benefits are two-fold, as I see it:
technorati tags: ResourceBundle, MissingResourceException, java
Posted at 08:55AM Apr 06, 2006 by chengfang in Glassfish | Comments[8]
Hi,
thanks, this post helped me a lot it gave some useful information for me.One thing I have a doubt, exactly the same problem I got but at the debugging time I gave full absolute path even also there is no positive result.
Posted by J.Naveen on May 19, 2008 at 08:05 PM EDT #
Hi,
I have a peculiar problem.. I am not getting this error, when the server is started.. it is working fine for sometime.
but as the page is used for a longer time, it throws me this error.
i hope there might be any database connection problems. But not sure whether it is the reason. Can anyone give an insight into this?
Posted by anandraj on May 26, 2008 at 09:43 AM EDT #
Gr8 way Just one sentence solved the problem... "resource properties files are loaded by classloader"... Thanks a lot. For explanation....
Posted by Kunal Handa on July 17, 2008 at 01:57 PM EDT #
I cannot find .properties files . I don't know how to create this properties files and include it in my project.
Posted by rahul ranjan on February 18, 2009 at 06:47 AM EST #
zxz
Posted by cxdsd on March 11, 2009 at 06:28 PM EDT #
sf
Posted by 202.91.140.4 on September 09, 2009 at 09:15 AM EDT #
That was a very good answer. Thanks a lot
Posted by Yashwanth on October 21, 2009 at 06:06 AM EDT #
asdsadsa
Posted by asdsad on November 11, 2009 at 08:32 AM EST #