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
Follow the hints in this post and see if you made one of those mistakes, which could be (copy pasted from the link):
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"
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");
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.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With