dcsimg
Reading from a properties file
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Antony_Ignatius
Posted On:   Monday, March 21, 2005 10:34 PM

Hi, I am writing a Java application for mailing. It requires reading from a properties file. I am using ResourceBundle bpBundle = ResourceBundle.getBundle("mailer"); where mailer.properties is the properties file. I am getting the following error: java.lang.ExceptionInInitializerError: java.util.MissingResourceException: Can't find bundle for base name mailer, locale en_US at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:724) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:695) at java.util.ResourceBundle.getBundle(ResourceBundle.java:558) at com.navistar.parts.nams.ut   More>>

Hi,


I am writing a Java application for mailing.
It requires reading from a properties file.

I am using

ResourceBundle bpBundle = ResourceBundle.getBundle("mailer");


where mailer.properties is the properties file.

I am getting the following error:


java.lang.ExceptionInInitializerError: java.util.MissingResourceException: Can't find bundle for base name mailer, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:724)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:695)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:558)
at com.navistar.parts.nams.util.AccountDeleteNotification. (AccountDeleteNotification.java:53)



Could any of you suggest what i need to be doing to specify where the mailer.properties file is?

   <<Less

Re: Reading from a properties file

Posted By:   Anonymous  
Posted On:   Thursday, April 21, 2005 09:56 AM


I had a similar problem finding the correct location for a ".properties" file .



In my case, it turns out java.util.ResourceBundle.getBundle() searches the -classpath [path(s)] used in the jvm/java invocation.




After putting my "things.properties" file in one of the paths(s); my issue went away.




If you don't have a "mailer.properties"; create one and keep fixing the exceptions as the arise in your stderr log/console.




Hope this helps,









James


Re: Reading from a properties file

Posted By:   Nathan_Ciliberto  
Posted On:   Wednesday, March 30, 2005 05:16 PM

From looking at the javadocs


http://java.sun.com/j2se/1.5.0/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String,%20java.util.Locale,%20java.lang.ClassLoader)


it looks like the it is looking for the file "mailer_en_US.properties" from the classpath.

Try this:

1) create the file "Resource.java" with the following code:


import java.util.ResourceBundle;

public class Resource {
public static void main( String[] args )throws Exception{
ResourceBundle bundle = ResourceBundle.getBundle( "mailer" );
System.out.println( "bundle="+ bundle + "." );
}
}


2) Create the file "mailer_en_US.properties" and put it in the same directory as "Resource.java"

3) compile the class:

javac -classpath . Resource.java


4) run it:

java -cp . Resource

Re: Reading from a properties file

Posted By:   David_Thornton  
Posted On:   Wednesday, March 23, 2005 05:26 PM

ResourceBundle.getBundle() is looking for mailer.properties in the folder that your application is launched from. If it is not in that folder but in a subfolder you need to specify the path, eg ResourceBundle bpBundle = ResourceBundle.getBundle("folder1.folder2.mailer");
About | Sitemap | Contact