Search code examples
javaeclipseinternationalizationresourcebundle

Cant find bundle for base name


I am trying a simple example of i18n in java but i am getting Can't find bundle for base name Resources/MessageBundle, locale en_US

This is my code

import java.util.ResourceBundle;

public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {

        ResourceBundle myResources =
                  ResourceBundle.getBundle("Resources/MessagesBundle");
            for (String s : myResources.keySet())
            {
                System.out.println(s);
            }
        // TODO Auto-generated method stub

    }

}

And this is my project structure http://oi62.tinypic.com/x5y4y8.jpg

Can anyone help me with this.I have added resource folder to java Build path


Solution

  • If you add the Resources directory to your build path, then this directory has to be considered as a root. Therefore, you'll find your bundle with :

    ResourceBundle myResources =
                  ResourceBundle.getBundle("MessageBundle");
    

    You have to know that ResourceBundle works with class loader, and the build path (or class path) sets the root of the class loader path.