MissingResourceException - Can't find bundle for base name
Hello,
I've been having problems getting a resource bundle to load. After looking through the current threads on the topic i'm still a little confused. Here is what i have:
--
Email.properties
shutdown=true
--
try
{
Locale locale =new Locale("en","US");
resources = ResourceBundle.getBundle("Email", locale);
}
catch (MissingResourceException mre)
{
mre.printStackTrace() ;
System.err.println("Email.properties not found");
System.exit(1);
}
Throws:
java.util.MissingResourceException: Can't find bundle for base name Email, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:804)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:773)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:538)
at com.dev.app.wes.common.email.TSndEmail.main(TSndEmail.java:187)
Email.properties not found
The file system structure is as follows:
C:\devjava\project\Email.properties
C:\devjava\project\classes\
and of course the source for the calling class is nested down in the package directory structure...com.dev.app.wes.common.email. Also when checking the current directory using new File(".") it results in c:\devjava\project\.
I have read about putting it in the classpath - is this something i do in eclipse or on the machine i'm using. I have tried appending the package name to the front of the base name(ie. com.dev.app.wes.common.email.email) but that didn't work either. Any help will be much appreciated.
-wdrone
[1993 byte] By [
wdronea] at [2007-10-1 23:01:17]

Ok, i have this working by putting the .properties file in the same directory as the .java file - unfortunately this is unacceptable because the properties file must remain outside the jar to allow for runtime manipulation. It has become clear though that it simply isn't looking in the right spot. Anyone know how to make this work better?
-wdrone
I've solved the problem the best way possible. Basically what i've done is added a new class folder named config to the project home dir. Then i added this classfolder to the classpath in project properties. After doing all of this you only need to reference the properties file by "Email".
Hope this helps anyone else who is having similiar problems.
I also had this problem. My Resource Bundle was in package StdOut and the class was called Messages. The code that called the resource bundle was also in package StdOut and was called ResourceTest.In ResourceTest, if I did...
ResourceBundle rb = ResourceBundle.getBundle("/Messages", Locale.getDefault());...
I would get the same message you did.
However, if you code ...
ResourceBundle rb = ResourceBundle.getBundle("StdOut/Messages", Locale.getDefault());
then everything works correctly.
Hello.
Has anybody come across this situation described below?
The resource bundle (let's call it B) is in package A. That is, it is called when the project is about to run as /A.B
The problem is that when the size of the file B gets really big (over 200 KB - i.e. 7500 rows of code) it seems that it can't be parsed.
So when I try to run the project I get this Exception:
"java.util.MissingResourceException: Can't find bundle for base name . . ." despite the fact that the file exists at the path specified (full path).
Does anyone know how I can overcome this error?
I m not too sure about ur exact problem but frm whtevr i understandU shall place properties file in same directory as ur java files are or in a directory that is accesible from this directory i mean subdirectory...all the best!!
a14a at 2007-7-15 13:58:24 >

Hello Friends,
I am getting error
Can't find bundle for bas c:/properties/source.properties.
I have one directory where i have all java files. and also property files.
I am trying to run it and getting error so i have put my property file in the c:\property\sorce.
I am trying to read this file using
propertyResources = ResourceBundle.getBundle("c:/properties/sourcelara.properties",Locale.getDefault());
but getting error.
can anyone help me please.
Thanks
Rupal
Rupala at 2007-7-15 13:58:24 >

i hope u have windows OS so insted of writng C:/abcd/abcd1/...just try by C:\\abcd\\avcd1\\... i hope it shall wrk.
a14a at 2007-7-15 13:58:24 >

To solve this issuemake the folder contains the resourse file (.xml or .properties) to be the FIRST one in the classpath.
I have my property file inside com.sample.resources file
and I am accessing this from other package .
I follow this code and it is working..
Client() {
try {
locale = new Locale("en", "US");
prop = ResourceBundle.getBundle(
"com/nwa/sample/resources/nocontainer-agency",
locale,
this.getClass().getClassLoader());
System.out.println(prop.getString("airline-agency-class"));
}
catch (MissingResourceException mre) {
mre.printStackTrace();
System.err.println("nocontainer-agency not found");
}
}
Hi!
In order to point it out again:
The tutorial file 'I18NSample.java' only works fine if the .properties files are stored in the default package. If not (in my case: 'language'), you have to add the package path:
Locale currentLocale = new Locale("de","DE");
ResourceBundle messages = ResourceBundle.getBundle("language/MessagesBundle", currentLocale);
Best regards, Sebastian Janke
This is what I just did:
package com.cinematica.cpUtils;
import java.util.*;
public class cp_mlStrings {
public String getString(String szStrName) {
ResourceBundle rb = ResourceBundle.getBundle("com.cinematica.cpUtils.LocalStrings", new Locale("es"));
String szStr = rb.getString(szStrName);
return(szStr);
}
}
Strange, but after hours it finally works.
Thanks a lot for your suggestions.
MissingResourceException is thrown for obvious reason. You don't have the resource on your classpath. But if you think you have, try to get the resource by:
this.getClass().getClassLoader().getResource("YOUR_RESOURCE.properties");
I am pretty sure you will get null in case you have this kind of exception. Therefore, go and check your classpath. Add necessary dirs to your classpath.
Hi naimdjon,My ResourceBundles are outside the ear. They have to exist in a completely different location. I have tried everything but still get MissingResourceException.I am directly trying to laod them in a Jsp.Please help!
I think the problem is that your ear is deployed by different classloader and the bundle is therefore not visible.
One thing you can try is to try to get the bundle with the classloader of your JSP, though it is a quite dirty hack.
getBundle(String baseName, Locale locale, ClassLoader loader).
Give me a reason why you have a bundle outside your ear and still you need to access it from within ear.
I am sorry, but I think you should consider redesigning.
Hi naimdjon,
Please give me more details on using:
getBundle(String baseName, Locale locale, ClassLoader loader)
We are considering keeping the ResourceBundle out of the ear, so that if any changes in text have to be made, the deployed ear doesn't have to be changed. Also some other group will be responsible for managing these bundles.
Really appreciate your help.
Hi naimdjon,Found another approach since the previous did not work.Added additional classpath to web.xml. Just used getBundle(String basename, Locale locale).... works now.
Another solution can be:
File file = new File("C:\\Properties\\configure.properties") ;
FileInputStream input = new FileInputStream(file);
java.util.PropertyResourceBundle propety = new java.util.PropertyResourceBundle(input);
Hi Wdrone,Your solution help me a lot.may I know where r u from ? and what are u doing?ThanksSrikantsatapathysrikant@gmail.com
This Particular Exception occurs basically when the location of the *.properties not being the part of the classpath at runtime.
The one solution i got is placing the *.propeties file in the a subfolder like config of the basedir and including the config dir into the classpath at runtime when done with Ant other wise
you need to explicitly set it in you classpath either thru a batch file or environmental path.
Hope this is of some use.
Regards
Emanuel