转:解决 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
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.
转:解决 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 init, locale zh_CN问题的处理
一.问题描述 项目开发使用的是SSM框架,项目那个正常运行,开发一个新功能后,添加了一些配置文件,再重新运行项目抛出异常,找不到name为init的bean. 二.异常信息详细 六月 30, 2018 ...
- java.util.MissingResourceException: Can't find bundle for base name db, locale zh_CN
在使用Bundle来加载配置文件的时候, 爆出了这个错误: 原因? 没有找到需要加载的配置文件,因为配置文件必须放在src目录下面, 如果放进了com.bj186.crm的包下面,就必须添加包的名称到 ...
- Caused by: java.util.MissingResourceException: Can't find bundle for base name javax.servlet.LocalStrings, locale zh_CN
这个是很早以前的一个bug了,最近开始用idea发现追源码相当方便,于是结合网上的解决方案以及自己的判断追踪一下原因,当然没有深究,只是根据提示一直追而已:先说一下解决方案: <dependen ...
- Java: MissingResourceException, "Can't find bundle for base name myMessage, locale zh_CN"
在java中,在多语言国际化时可以用 *.java 类来作为资源文件使用. 1. 首先定义类, 类必须继承ListResourceBundle 类所在路径为: src/I18N public clas ...
- java.util.MissingResourceException: Can't find resource for bundle oracle.sysman.db.rsc.LoginResourc
http://blog.itpub.net/197458/viewspace-1055358/ oracle 10.2.0.4 windows 2003 X64 平台 系统安装EMCA正常.第一次 ...
- java读取package中的properties文件java.util.MissingResourceException
文件结构: /build/classes/d914/Hello.class /build/classes/d914/mess.properties /build/classes/d914/mess_z ...
- 谈论高并发(二十二)解决java.util.concurrent各种组件(四) 深入了解AQS(二)
上一页介绍AQS其基本设计思路以及两个内部类Node和ConditionObject实现 聊聊高并发(二十一)解析java.util.concurrent各个组件(三) 深入理解AQS(一) 这篇说一 ...
- (转)p解决 java.util.prefs.BackingStoreException 报错问题
原文:https://blog.csdn.net/baidu_32739019/article/details/78405444 https://developer.ibm.com/answers/q ...
- spark 解决 java.util.Date is not a valid external type for schema of Date
出错伪代码如下: //出错的点在这里 import java.util.Date ... val t_rdd = t_frame.rdd.map(row => { val photo_url = ...
随机推荐
- linux下检测可用串口并使用minicom打开
目前使用minicom作为串口软件.但使用过程中,有一点感觉不方便的地方,就是我需要使用多个串口,当使用的不是串口0时,就要手动修改minicom的配置. 于是考虑实现脚本,自动列出当前串口,选择后调 ...
- JMeter之定时器的作用域
定时器的作用域 1.定时器是在每个sampler(采样器)之前执行的,而不是之后(无论定时器位置在sampler之前还是下面): 2.当执行一个sampler之前时,所有当前作用域内的定时器都会被执行 ...
- Maven介绍---POM、Dependency Management、Coordinates
Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建.报告和文档的软件项目管理工具. POM(Project Object Model,对象模型): 仅仅只是一个xml配置文 ...
- String类的常见方法的使用案例
String类的常见方法的使用案例 //使用指定的字符串替换当前字符串中指定的内容 //将helloworld中的o替换为a String s="HelloWorld"; Stri ...
- poj 1584(综合性强的计算几何,好题)
A Round Peg in a Ground Hole Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6238 Acc ...
- 微信小程序自动去除input空格的方法
当用户输入账号或者密码的时候,可能会有输入空格的情况,但是实际需要是不能够有空格的,所以我们要做一个去除空格,并且适应所有input的name参数的方法,下面请看源码: wxml: <input ...
- yii2.0在model里自定义数据表
无需多言,直接撸代码 class Zhuanjia extends \yii\db\ActiveRecord { public static function tableName() { return ...
- hdu5794
从(u,v)到(n,m)相当于走x步1*2和y步2*1满足 x+2y=n-u,2x+y=m-v 解方程然后组合计数即可. 以前没写过lucas定理,写一下…… 其实就是C(n,m)%p=C(n/p,m ...
- (九)expect批量公钥推送
(1)expect实现ssh非交互登录 注意:注释不能出现这脚本里面 spawn表示开启一个会话 \r:表示回车,exp_continue :表示没有出现这样,继续往下执行 interact :停留在 ...
- Mysql错误:Every derived table must have its own alias
Mysql报错:Every derived table must have its own alias <缺少一个别名> 在子查询中经常会犯的错误 .这个别名其实没啥用途.... ...