Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
来源:互联网 发布:淘宝运营规划方案 编辑:程序博客网 时间:2024/04/29 01:13
Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)
You know java is looking for a properties file in a specific locale. You may be baffled why java keeps complaining it can't find a properties file that is right there. A few things to keep in mind when debugging this type of errors:
- 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"
For instance, you have a project like
C:/ws/netbeans5/scrap>
| build.xml
+---build
| /---classes
| /---com
| /---cheng
| /---scrap
| Scrap.class
|
+---src
| /---com
| /---cheng
| /---scrap
| config.properties
| Scrap.java
For this statement in Scrap.java: ResourceBundle config = ResourceBundle.getBundle("config");
to work, you will need to cp src/com/cheng/scrap/config.properties build/classes/
such that config.properties
is directly under classes
, and at the same level as com
. Alternatively, you can put config.properties
into a config.jar
such that config.properties
is at the root of config.jar
without any subdirectories, and include config.jar
in the classpath.
For this statement in Scrap.java: ResourceBundle config = ResourceBundle.getBundle("com.cheng.scrap.config");
to work, you will need to cp src/com/cheng/scrap/config.properties build/classes/
com/cheng/scrap/
such that config.properties
is directly under classes
/
com/cheng/scrap/
, and at the same level as scrap
. Alternatively, you can put com/cheng/scrap/
config.properties
(along with the long subdirectories) into a config.jar
, and include
config.jar
in the classpath.
You may be wondering why it is made so confusing? The benefits are two-fold, as I see it:
- Location transparency. At runtime, config.properties is NOT a file, it's just a a loadable resource. config.properites may not exist in your project at all, and the person who wrote Scrap.java may have never seen this resource. A URLClassLoader can find it in a network path or URL at runtime. This is especially important for server-side components such as EJB, Servlet, JSP, etc, who are normally not allowed to access file systems. When you ask classloaders for a resource, its physical location becomes irrelevant.
- Namespace mechanism. Having a package allows multiple packages to have resources with the same short name without causing conflicts. This is no different from java packages and xml namespaces.
- Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
- Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
- 解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误
- 转:解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误
- java.util.MissingResourceException: Can't find bundle for base name i18n, locale zh_CN
- JSF java.util.MissingResourceException: Can't find bundle for base name javax.faces.Messages, locale zh_CN
- 关于:java.util.MissingResourceException: Can't find bundle for base name merchantInfo, locale zh_CN
- 解决java.util.MissingResourceException: Can't find bundle for base name configContext, locale zh_CN
- java.util.MissingResourceException: Can't find bundle for base name
- java.util.MissingResourceException: Can't find bundle for base name
- 解决 java.util.MissingResourceException: Can't find bundle for base name com...con
- Can't find bundle for base name configure, locale zh_CN
- Can't find bundle for base name Message, locale zh_CN
- Can't find bundle for base name configure, locale zh_CN
- Can't find bundle for base name MessageResource, locale zh_CN
- Configuration Error: Can't find bundle for base name src.config.lvg, locale zh_CN
- Notes for "java.util.MissingResourceException Can't find bundle for base name"
- 解决方法:java.util.MissingResourceException Can't find bundle for base name
- C# 读取图片上面的文字
- 『分享』各种提示、输入对话框的使用
- 条款26:尽可能延后变量定义式的出现时间
- Developer Express一些小技巧
- C# 实现的多线程异步Socket数据包接收器框架(来源http://www.cnblogs.com/wcfgroup/archive/2008/10/06/1304512.html)
- Solve java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN
- 【练手】cube和grouping的分组统计
- STL测试
- 解密淘宝网的开源架构
- insert into 和insert into select性能比较
- sql 实现记录有重复只显示一条。
- 通过轮询数据源数据行状态更新数据库
- 关于stream的初步认识
- Linux软件安装及卸载