关于 resourcebundle 错误,我已经阅读了有关同一主题的其他问题,但我没有得到任何更明智的信息。尝试了不同的东西,没有帮助。提供一点背景知识:我开发了一个小应用程序(JDK6),它可以自动进行一些平面文件的解析和编辑。该应用程序首先从属性文件中读取一些数据。
重要提示:我希望能够更改属性文件。我不想把它放在 jar 文件中。
但是,即使使用我尝试创建的小示例应用程序,基于另一个问题/答案 [这里][1]:
package restestapp;
import java.util.Locale;
import java.util.ResourceBundle;
public class ResourceBundleTester
{
public static void main(String[] args)
{
Locale locale = Locale.getDefault();
String basename ="myresource";
ResourceBundle resourceBundle = ResourceBundle.getBundle(basename, locale);
System.out.println(resourceBundle.getString("STARTING_MYAPP"));
}
}
两个文件都在这里:
/home/dakoina/Documents/ResTestapp/ResTestApp.jar
/home/dakoina/Documents/ResTestapp/myresource.properties
甚至
c:/temp/ResTestApp.jar
c:/temp/myresource.properties
但是当我运行它时,它给了我这个输出:
dakoina@ubuntu:~/Documents/ResTestapp$ java -cp /home/dakoina/Documents/ResTestapp/ -jar "ResTestApp.jar"
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name myresource, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1539)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1278)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:805)
at restestapp.ResTestApp.main(ResTestApp.java:19)
在 Windows 中,同样...
c:\temp>java -jar ResTestApp.jar
Exception in thread "main" java.util.MissingResourceException: Can't find bundle
for base name myresource, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at restestapp.ResTestApp.main(ResTestApp.java:19)
[1]: http://stackoverflow.com/questions/3742158/using-resourcebundle-with-an-external-file-java
我看不出我错在哪里:/