[英]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
我正在尝试在Java中使用i18n的一个简单示例,但我却
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 这是我的项目结构http://oi62.tinypic.com/x5y4y8.jpg
Can anyone help me with this.I have added resource folder to java Build path 谁能帮我这个忙。我已经将资源文件夹添加到Java Build路径中
If you add the Resources directory to your build path, then this directory has to be considered as a root. 如果将Resources目录添加到构建路径,则必须将该目录视为根目录。 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. 您必须知道ResourceBundle与类加载器一起使用,并且构建路径(或类路径)设置了类加载器路径的根。
You do not need the Resources/
您不需要
Resources/
ResourceBundle.getBundle("MessageBundle");
From javadoc : 从javadoc:
baseName - the base name of the resource bundle, a fully qualified class name
baseName-资源包的基本名称,完全限定的类名称
As Resources
seems to be in your class path, it should work. 由于
Resources
似乎在您的课程路径中,因此它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.