`
sunnychuh
  • 浏览: 22226 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

解决 java.util.MissingResourceException: Can't find bundle for base name com...con

阅读更多

转:解决 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.

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/nickshen3/archive/2007/07/19/1698261.aspx

分享到:
评论

相关推荐

    Tomcat内存溢出的解决方法(java.util.concurrent.ExecutionException)

    "java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError" 是一个典型的错误提示,它表明在并发执行过程中遇到了内存不足的问题。下面我们将深入探讨这个问题的原因、影响以及如何解决。 内存溢出...

    JAVA中关于String的一些注意点

    ### JAVA中关于String的一些注意点 在Java编程语言中,`String` 类是最常用的数据类型之一,用于处理文本数据。本文将深入探讨Java中的`String`类及其使用时需要注意的关键点,希望对开发者们有所帮助。 #### 1. ...

    org.apache.jasper.JasperException: java.util.MissingResourceException 解决方案

    在Java Web开发中,我们经常会遇到“org.apache.jasper.JasperException: java.util.MissingResourceException”这样的错误。这个异常通常发生在尝试访问一个不存在的资源文件时,比如国际化(i18n)配置文件。本文...

    java.util.logging.Logger使用详解

    ### Java.util.logging.Logger 使用详解 #### 一、创建Logger对象 在Java中,`java.util.logging.Logger` 是标准的日志框架之一,它提供了基础的日志记录功能。为了使用这一功能,首先需要获得 `java.util.logging...

    java.util.Date与java.sql.Date互转及字符串转换为日期时间格式.docx

    ### Java.util.Date与Java.sql.Date互转及字符串转换为日期时间格式 #### 一、Java.util.Date与Java.sql.Date的基本概念 在Java编程语言中,处理日期和时间时经常使用到`java.util.Date`和`java.sql.Date`这两个类...

    最最常用的 100 个 Java类分享

    1. `java.util.ArrayList`:ArrayList是Java集合框架中的一种动态数组,它允许快速的元素访问,但插入和删除操作相对较慢。 2. `java.io.IOException`:这是所有I/O异常的基类,用于处理输入/输出操作中的错误。 3...

    java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream解决方法

    JavaMail的java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream错误 原因: MyEclipse6.5的javaee.jar中的mail包与JavaMail包有冲突。 解决: 在MyEclipse目录下(D:\Program Files\MyEclipse ...

    java.util.Date与java.sql.Date相互转换

    ### Java.util.Date与Java.sql.Date相互转换 #### 知识点概述 在Java开发中,经常需要处理日期和时间相关的操作。Java标准库提供了两个重要的日期类:`java.util.Date` 和 `java.sql.Date`。虽然它们名字相似,但...

    用java.util.zip包现数据压缩与解压

    ### 使用 Java.util.zip 包实现数据压缩与解压 在计算机科学领域,数据压缩技术是一项重要的功能,它能够帮助减少存储空间的需求以及提高网络传输效率。本文将通过一系列的示例来详细介绍如何利用 Java 中的 `java....

    java并发工具包 java.util.concurrent中文版用户指南pdf

    1. java.util.concurrent - Java 并发工具包 2. 阻塞队列 BlockingQueue 3. 数组阻塞队列 ArrayBlockingQueue 4. 延迟队列 DelayQueue 5. 链阻塞队列 LinkedBlockingQueue 6. 具有优先级的阻塞队列 ...

    Tomcat启动时报错:java.lang.UnsatisfiedLinkError的解决

    解决方法 后面我把原先tomcat启动环境用的jdk1.7改为了本机安装的jdk1.8就不在报错。 具体过程: 在myeclipse中点击window→preference→在搜索框中输入Tomcat→选择安装的tomcat版本,我这里是选择Tomcat 7.x→点击...

    resources_cn安卓工作室android studio 2.3.3中文汉化包_韩梦飞沙.jar

    Can't find resource for bundle java.util.PropertyResourceBundle, key emmet.bem.class.name.element.separator.label 安卓工作室 android studio 版本 2.3.3。 还有美化,修改 定制 教程。作者:韩梦飞沙。邮箱...

    java.util包

    Java.util包是Java标准库中的核心包之一,它包含了大量用于通用编程的类和接口,是Java开发中不可或缺的一部分。这个包提供了数据结构、集合框架、事件处理、日期时间、随机数生成、位集以及与I/O流操作相关的辅助...

    tomcat启动报错:java.util.zip.ZipException的解决方法

    在使用Apache Tomcat服务器时,有时会遇到启动异常的情况,其中一种常见的错误是`java.util.zip.ZipException`。这个异常通常表明在处理ZIP或JAR文件时遇到了问题,可能是因为文件损坏、格式不正确或者无法打开。在...

    java.sql.date与java.util.date.pdf

    Java编程语言中,`java.util.Date` 和 `java.sql.Date` 都是用来处理日期的类,但它们在用途和特性上有所不同。理解这两者之间的差异对于进行数据库操作至关重要。 1. **`java.util.Date`**: - `java.util.Date` ...

    org.jasig.cas.client.util.CommonUtils

    予org.jasig.cas.client.util.CommonUtils 加入 public static void disableSSLVerification(){ try { // Create a trust manager that does not validate certificate chains TrustManager[] ...

    java.util.ConcurrentModificationException 解决方法

    java.util.ConcurrentModificationException 解决方法 在使用iterator.hasNext()操作迭代器的时候,如果此时迭代的对象发生改变,比如插入了新数据,或者有数据被删除。 则使用会报以下异常: Java.util....

Global site tag (gtag.js) - Google Analytics