Java 1.5、Java EE 5、WAS 6.1:使用 ResourceBundle.getBundle(...) 加载资源包时出现异常
这是我们在将应用程序从当前生产环境迁移到新数据中心环境时面临的另一个问题(请参阅下面的详细信息)
- 当前生产环境: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)
我们尝试了以下解决方法,但没有成功:
- 将 db.properties 重命名为 db_en_US.properties
- jar 中
- 将属性文件放入移动的 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)
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:
- Renamed the db.properties as db_en_US.properties
- Putting the properties file in the jar
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在您的 ent 设置中更改类加载器顺序。 EAR 和 WAR 级别的管理控制台中的应用程序(从
PARENT_FIRST
到PARENT_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
toPARENT_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.
您是否尝试过将 db.properties 文件放在 WEB-INF/classes 目录下?
Have you tried putting your db.properties file under WEB-INF/classes directory?