简体   繁体   English

Java 1.5,Java EE 5,WAS 6.1:使用ResourceBundle.getBundle(…)加载资源束的异常

[英]Java 1.5, Java EE 5, WAS 6.1: Exception loading a resource bundle with ResourceBundle.getBundle(…)

Here's another issues that we are facing while migrating our application from current production environment to the new data center environment (see details below) 在将应用程序从当前生产环境迁移到新的数据中心环境时,这是我们面临的另一个问题(请参见下面的详细信息)

  • Current Production Environment : Java 1.4, Java EE 3, WAS 5.1, JSF 2.1 当前的生产环境:Java 1.4,Java EE 3,WAS 5.1,JSF 2.1
  • New Environment: Java 1.5, Java EE 5, WAS 6.1, JSF 2.1 新环境:Java 1.5,Java EE 5,WAS 6.1,JSF 2.1

Here we have a third party jar file with the following structure (check the image - pardon me hiding some details) 这里我们有一个具有以下结构的第三方jar文件(检查图像-请原谅我隐藏了一些细节)
替代文字


This class has the code to load the database properties from a ResourceBundle (db.properties). 此类具有从ResourceBundle(db.properties)加载数据库属性的代码。 Here is the code rendered out by Cavaj: 这是Cavaj提供的代码:

private static ResourceBundle getDBProperties()
    {
        if(dbProperties == null)
        {
            dbProperties = ResourceBundle.getBundle("db");
        }
        return dbProperties;
    }

This application is working fine on the current environment. 该应用程序在当前环境下运行良好。 But somehow when we move the application to the new environment we get a "MissingResourceException" (see below): 但是以某种方式,当我们将应用程序移至新环境时,会得到“ MissingResourceException”(如下所示):

Caused by: java.util.MissingResourceException: Can't find bundle for
base name db, locale en_US
at
java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:863)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:832)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)
at
com.myco.wo.vs.util.OrderLovUtilities.getDBProperties(OrderLovUtilities.java:195)

We tried following workarounds but none worked: 我们尝试了以下解决方法,但没有一个起作用:

  1. Renamed the db.properties as db_en_US.properties 将db.properties重命名为db_en_US.properties
  2. Putting the properties file in the jar 将属性文件放入罐子中
  3. moving the jar file at EAR level. 将jar文件移到EAR级别。

Please suggest on what could be wrong here. 请在这里提出可能有问题的建议。 And what can we do to get it working :) 而我们该怎么做才能使其正常工作:)

Note: File db.properties is located under the WEB-INF/classes directory. 注意:文件db.properties位于WEB-INF / classes目录下。 Also we tried putting it on the above mentioned locations but to no avail. 我们也尝试将其放在上述位置,但无济于事。

Regards, 问候,
- Ashish -Ashish

Try to change classloader ordering in settings of your ent. 尝试在您的耳鼻喉科的设置中更改类加载器的顺序。 application in the admin console (from PARENT_FIRST to PARENT_LAST ) on both EAR and WAR levels. EAR和WAR级别的管理控制台中的应用程序(从PARENT_FIRSTPARENT_LAST )。

It seems to me that 3rd party class ( com.myco.wo.vs.util.OrderLovUtilities ) is not loaded from your jar file in WEB-INF/lib, but it is rather comes from some other location on the server. 在我看来,第3方类( com.myco.wo.vs.util.OrderLovUtilities )并不是从WEB-INF / lib中的jar文件加载的,而是来自服务器上的其他位置。 Its classloader then does not see the property file. 然后,其类加载器看不到属性文件。

If that is the issue, changing the classloader ordering should cause the expected copy of the class to load. 如果这是问题所在,则更改类加载器的顺序应会导致加载类的预期副本。

Also, the classloader viewer in the admin console can put some light on that. 同样,管理控制台中的类加载器查看器可以对此进行一些说明。

您是否尝试过将db.properties文件放在WEB-INF / classes目录下?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM