Java 1.5、Java EE 5、WAS 6.1:使用 ResourceBundle.getBundle(...) 加载资源包时出现异常

发布于 2024-07-18 17:47:30 字数 1461 浏览 2 评论 0原文

这是我们在将应用程序从当前生产环境迁移到新数据中心环境时面临的另一个问题(请参阅下面的详细信息)

  • 当前生产环境:Java 1.4、Java EE 3、WAS 5.1、JSF 2.1
  • 新环境:Java 1.5、Java EE 5、WAS 6.1、JSF 2.1

这里我们有一个具有以下结构的第三方 jar 文件(检查图像 - 请原谅我隐藏了一些细节)
替代文本


此类具有从 ResourceBundle (db.properties) 加载数据库属性的代码。 以下是 Cavaj 呈现的代码:

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

该应用程序在当前环境中运行良好。 但不知怎的,当我们将应用程序移动到新环境时,我们得到一个“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)

我们尝试了以下解决方法,但没有成功:

  1. 将 db.properties 重命名为 db_en_US.properties
  2. jar 中
  3. 将属性文件放入移动的 EAR 级别的 jar 文件。

请提出这里可能出现问题的建议。 我们可以做些什么来让它工作:)

注意: 文件 db.properties 位于 WEB-INF/classes 目录下。 我们也尝试将其放在上述位置但无济于事。

问候,
- 阿什什

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
  • New Environment: 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)
alt text

This class has the code to load the database properties from a ResourceBundle (db.properties). Here is the code rendered out by 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):

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
  2. Putting the properties file in the jar
  3. moving the jar file at EAR level.

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. Also we tried putting it on the above mentioned locations but to no avail.

Regards,
- Ashish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾听心声的旋律 2024-07-25 17:47:30

尝试在您的 ent 设置中更改类加载器顺序。 EAR 和 WAR 级别的管理控制台中的应用程序(从 PARENT_FIRSTPARENT_LAST)。

在我看来,第 3 方类(com.myco.wo.vs.util.OrderLovUtilities)不是从 WEB-INF/lib 中的 jar 文件加载的,而是来自其他一些类服务器上的位置。 然后它的类加载器看不到属性文件。

如果这是问题所在,则更改类加载器顺序应该会导致加载类的预期副本。

此外,管理控制台中的类加载器查看器可以对此进行一些说明。

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.

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. 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.

‖放下 2024-07-25 17:47:30

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

Have you tried putting your db.properties file under WEB-INF/classes directory?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文