Tomcat\bin 文件夹中的属性文件获取 java.util.MissingResourceException

编程入门 行业动态 更新时间:2024-10-09 18:23:16
本文介绍了Tomcat\bin 文件夹中的属性文件获取 java.util.MissingResourceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想使用 ResourceBundleTomcat\bin 文件夹中读取属性文件.当我将我的属性文件放在项目的根文件夹中时,我能够读取这个文件.但是当我把它放在 Tomcat\bin 文件夹中时,我得到了 java.util.MissingResourceException.这是怎么引起的,我该如何解决?

I want to read a properties file from Tomcat\bin folder using ResourceBundle. When I put my properties file in project's root folder, I am able to read this file. But when I put it in Tomcat\bin folder, I'm getting java.util.MissingResourceException. How is this caused and how can I solve it?

推荐答案

你需要把它放在类路径中.Tomcat/bin 文件夹不是 web 应用程序的默认运行时类路径的一部分.如果您打算在 Tomcat 中运行的 webapp 的类路径中添加一个外部文件夹,那么您需要在 Tomcat/conf/的 shared.loader 属性中指定该文件夹的路径catalina.properties 文件.但是,我会选择与 Tomcat/bin 不同的文件夹.

You need to put it in the classpath. The Tomcat/bin folder is not part of the webapp's default runtime classpath. If you intend to add an external folder to the classpath of a webapp running in Tomcat, then you need to specify the path to that folder in the shared.loader property of the Tomcat/conf/catalina.properties file. I would however choose a different folder than the Tomcat/bin.

与问题无关ResourceBundle API 旨在读取资源包文件(具有本地化内容,以便您可以国际化您的应用程序),而不是读取简单的属性文件(带有配置设置).为此,您应该使用 java.util.属性 而不是滥用 java.util.ResourceBundle.

Unrelated to the problem, the ResourceBundle API is meant to read resourcebundle files (with localized content so that you can internationalize your app), not to read simple properties files (with configuration settings). For that you should be using java.util.Properties instead and not abuse the java.util.ResourceBundle.

Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/config.properties"));
// ...

这篇关于Tomcat\bin 文件夹中的属性文件获取 java.util.MissingResourceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 03:44:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1388954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   属性   夹中   bin   Tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!