java.util.MissingResourceException
我在运行应用程序时遇到异常。该应用程序读取abc.properties文件,
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name abc, locale en_US at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:853) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:822) at java.util.ResourceBundle.getBundle(ResourceBundle.java:566) at com.ibm.dst.DailyExtract.getResourceBundle(DailyExtract.java:104) at com.ibm.dst.DailyExtract.main(DailyExtract.java:131)
abc.properties文件驻留在工作空间中。 我使用RSA7作为IDE,有什么设置问题吗? 欢迎任何建议......
提前非常感谢
I am getting below exception while running an application. This application read abc.properties file,
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name abc, locale en_US at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:853) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:822) at java.util.ResourceBundle.getBundle(ResourceBundle.java:566) at com.ibm.dst.DailyExtract.getResourceBundle(DailyExtract.java:104) at com.ibm.dst.DailyExtract.main(DailyExtract.java:131)
abc.properties file reside at the workspace.
I am using RSA7 as IDE, is there any setting problem?
any suggestions are welcome.....
Thanks a lot in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
按照这篇文章中的提示,看看您是否犯了其中一个错误,这可能是(从链接复制粘贴):
这些资源属性文件由类加载器加载,类似于java类。因此,您需要将它们包含在运行时类路径中。
这些资源具有完全限定资源名称,类似于完全限定类名称,摘录您无法将资源导入到 java 源文件中。为什么?因为它的名称采用字符串的形式。
ResourceBundle.getBundle("config")
告诉类加载器使用默认包(即无包)加载名为“config”的资源。它并不意味着当前包中具有引用类的资源。ResourceBundle.getBundle("com.heng.scrap.config")
告诉类加载器加载名为“config”且包为“com.heng.scrap”的资源。它的完全限定资源名称是“com.heng.scrap.config”Follow the hints in this post and see if you made one of those mistakes, which could be (copy pasted from the link):
These resource properties files are loaded by classloader, similar to java classes. So you need to include them in your runtime classpath.
These resources have fully-qualified-resource-name, similar to a fully-qualified-class-name, excerpt you can't import a resource into your java source file. Why? because its name takes the form of a string.
ResourceBundle.getBundle("config")
tells the classloader to load a resource named "config" with default package (that is, no package). It does NOT mean a resource in the current package that has the referencing class.ResourceBundle.getBundle("com.cheng.scrap.config")
tells the classloader to load a resource named "config" with package "com.cheng.scrap." Its fully-qualified-resource-name is "com.cheng.scrap.config"您只需要在获取文件时添加包名称
例如,如果您的属性名称是包 abc 中的“ABC.properties”,那么下面的代码将完美运行
You just need to add the package name while getting the file
For example if your properties name is "ABC.properties" in package a.b.c then the below code will work perfectly
只需将资源文件复制到类文件所在的位置即可。
就我而言,我的目录是:
将资源文件复制到 bin 文件夹。
Just copy the resource file over to where your class files are.
In my case my directory was:
copy your resource file to the bin folder.
加载本地化内容的属性文件也会受到包命名的影响。如果您将属性文件放在像
org.example.com.foobar
这样的包中,并仅通过其名称abc
加载它,则必须添加前缀org.properties 文件。 example.com.foobar 也是如此。如果属性位于不同位置(例如在根目录或另一个子目录中),则必须更改要加载的名称或类路径。
我将属性文件放置在
.java
文件所在的同一位置并使用类似的东西运行良好Loading the Properties file for localization stuff is also affected by the package naming. If you put your Properties file in a package like
org.example.com.foobar
and load it just by its nameabc
you have to add the prefixorg.example.com.foobar
, too. If you have the properties at a different location (like in the root directory or in another subdir) you have to change either the name to load or the classpath.I run fine in placing the properties file in the same location where the
.java
file is and using something like今天我遇到了同样的问题,我花了一段时间才找到解决方案(我使用 Eclipse 作为 IDE)。我的项目文件夹包含以下路径中的 *.properties-Files:
由于 strings 是 src 的子文件夹,并且 src 已经在项目的构建路径中(请参阅属性窗口),所以我需要的只是添加一个包含 - *.properties-Files 的模式:
应该已经有一个 *.java-Files (**/*.java) 的包含模式,
也许您的 IDE 有类似的东西
I had the same issue today and it took me a while until I figured out a fix (I'm using Eclipse as an IDE). My project folder contains the *.properties-Files in the following path:
Since strings is a sub-folder of src and src is already in the build path of the project (see Property Window), all I needed was to add an Inclusion-Pattern for the *.properties-Files:
There should be already an Inclusion-Pattern for *.java-Files (**/*.java)
Maybe there is something similar for your IDE
该文件在您的类路径中吗?如果是,请尝试将其重命名为 abc_en_US.properties
Is the file in your classpath? If it is, try renaming it to abc_en_US.properties