Rick
Rick

Reputation: 17013

Loading a Java .properties file, getting java.util.MissingResourceException: Can't find bundle for base name what am I doing wrong?

I'm new to loading a custom .properties file and am doing so from within my Spring MVC app.

I have a properties file at: com.company.wtwebapp.properties.wtwebapp.properties

I have tried as below as well as a variety of combinations (leaving out the src.main.java, using "/" instead of ".") but nothing works.

          ResourceBundle rb = ResourceBundle.getBundle
          ("src.main.java.com.company.wtwebapp.properties.wtwebapp.properties");

On my classpath file I have:

<classpathentry kind="lib" path="src/main/java/com/company/wtwebapp/properties/wtwebapp.properties"/>

I always get the error:

java.util.MissingResourceException: Can't find bundle for base name src.main.java.com.company.wtwebapp.properties.wtwebapp.properties, locale en_US

I would appreciate any advice on the proper way / better way to accomplish the loading of the properties file. I have been doing a lot of searches but they are just leading to more confusion as from what I can tell what I am doing should be working (but obviously something is wrong). Thanks

Upvotes: 0

Views: 4127

Answers (2)

Perception
Perception

Reputation: 80593

Try loading your resource bundle like this:

ResourceBundle rb = ResourceBundle.getBundle("com.company.wtwebapp.properties.wtwebapp");

And modify your classpath entry like so:

<classpathentry kind="lib" path="src/main/java"/>

Upvotes: 0

Jim Garrison
Jim Garrison

Reputation: 86754

From the javadoc:

getBundle attempts to locate a property resource file. It generates a path name from the candidate bundle name by replacing all "." characters with "/" and appending the string ".properties".

You are supposed to provide the basename only; remove the .properties suffix. Also if the bundle is in the same directory as the class, remove all the path information.

Upvotes: 1

Related Questions