Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.util.MissingResourceException: Can't find bundle for base name messages, locale en_US

I am new to JSF an was trying out this piece of code.. This is my faces-config.xml:

<application>
        <resource-bundle>
            <base-name>messages</base-name>
            <var>msg</var>
        </resource-bundle>
    </application>

messages is a file that stores a few properties and messages file is not placed under any directory, it is placed directly under the application. Why cant i access this file? Thank you in advance.. please do let me know if you need any additional information..

like image 534
digvijay Avatar asked Jun 07 '12 06:06

digvijay


People also ask

How do I fix Java Util MissingResourceException?

To fix the MissingResourceException , it should be ensured that any resource required by the program exists with the correct name and at the right location. Any values attempted to be retrieved from a resource file using a key should exist with the right key.

How do you create a resource bundle in Java?

Creating a ResourceBundle You create a ResourceBundle instance like this: Locale locale = new Locale("en", "US"); ResourceBundle labels = ResourceBundle. getBundle("i18n. MyBundle", locale); System.

How do I use ResourceBundle getBundle?

getBundle. Gets a resource bundle using the specified base name, locale, and class loader. This method behaves the same as calling getBundle(String, Locale, ClassLoader, Control) passing a default instance of ResourceBundle.


2 Answers

looks like your file placed in some package inside your src folder

<base-name>some.package.name.Messages</base-name>

also make sure the file called Messages.properties

b.t.w are you aware that Messages.properties file will allow you to override your validators error messages?

Also, take a look at this nice tutorial JSF 2 message and messages example

like image 151
Daniel Avatar answered Sep 27 '22 23:09

Daniel


If you put it in directly into src folder it should work. Athough I would suggest to organize the message files in packages.

like image 32
1337 Avatar answered Sep 27 '22 23:09

1337