由于类加载器配置而导致 MissingResourceException(调用者不在 WEB-INF/classes 中)
访问资源包时出现 MissingResourceException。由于我的特定类加载器星座而出现问题。
我正在尝试从位于 JBOSS_HOME/server/myServer/myDeployDir/myEAR/myJAR.jar 下的类中读取 text.properties (注意:调用类不在 WEB-INF/classes 中)。 text.properties 文件位于 JBOSS_HOME/server/myServer/myDeployDir/myEAR/myWAR/WEB-INF/classes。
运行以下代码时:
Locale locale = new Locale ("de", "DE");
ResourceBundle rb = ResourceBundle.getBundle(textproperties, locale);
我得到以下内容
java.util.MissingResourceException: Can't find bundle for base name text, locale de_DE.
不幸的是,我不能更改应用程序的结构。我既不能将调用者类(现在在 myJAR.jar 中)移动到 WEB-INF/classes,也不能将属性文件打包到 myJAR.jar 中。有没有办法从 WEB-INF/classes 外部访问属性文件?
该应用程序在 JBOSS 4.2.3 上运行,因此我想我必须牢记 Web 服务器线程处理。
感谢您提前的帮助, 贡纳尔
I get a MissingResourceException when accessing a resource bundle. The problem comes up due to my specific class loader constallation.
I am trying to read a text.properties from within a class which resides under JBOSS_HOME/server/myServer/myDeployDir/myEAR/myJAR.jar (note: the calling class is not in WEB-INF/classes). The text.properties file is here JBOSS_HOME/server/myServer/myDeployDir/myEAR/myWAR/WEB-INF/classes.
When running the following code:
Locale locale = new Locale ("de", "DE");
ResourceBundle rb = ResourceBundle.getBundle(textproperties, locale);
I get the following
java.util.MissingResourceException: Can't find bundle for base name text, locale de_DE.
Unfortunately, I must NOT change the structure of my application. I can neither move the caller class (now in myJAR.jar) to WEB-INF/classes, or can I pack the properties file into myJAR.jar. Is there any way to access the properties file from outside WEB-INF/classes?
The application runs on JBOSS 4.2.3, so I guess I have to keep web-server thread handling in mind.
Thanks for your help in advance,
Gunnar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以指定类加载器用作 getBundle。在 Web 应用程序中,这很可能是当前线程的上下文类加载器:
You can specify the classloader to use as an additional parameter to getBundle. In a web application this would most likely be the context class loader of the current thread: