简体   繁体   English

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

[英]Property file in Tomcat\bin folder getting java.util.MissingResourceException

I want to read a properties file from Tomcat\\bin folder using ResourceBundle . 我想使用ResourceBundleTomcat\\bin文件夹中读取属性文件。 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 . 但是当我把它放在Tomcat\\bin文件夹中时,我得到的是java.util.MissingResourceException How is this caused and how can I solve it? 这是怎么造成的,我该如何解决?

You need to put it in the classpath. 您需要将它放在类路径中。 The Tomcat/bin folder is not part of the webapp's default runtime classpath. Tomcat/bin文件夹不是webapp的默认运行时类路径的一部分。 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. 如果要将外部文件夹添加到在Tomcat中运行的webapp的类路径中,则需要在Tomcat/conf/catalina.properties文件的shared.loader属性中指定该文件夹的路径。 I would however choose a different folder than the Tomcat/bin . 然而,我会选择与Tomcat/bin不同的文件夹。


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). 此问题无关ResourceBundle API旨在读取resourcebundle文件(具有本地化内容以便您可以使应用程序国际化),而不是读取简单属性文件(使用配置设置)。 For that you should be using java.util.Properties instead and not abuse the java.util.ResourceBundle . 为此,您应该使用java.util.Properties而不是滥用java.util.ResourceBundle

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

暂无
暂无

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

相关问题 java.util.MissingResourceException: - java.util.MissingResourceException: java.util.MissingResourceException - java.util.MissingResourceException 当访问属性文件时,Spring Boot java.util.MissingResourceException - Spring boot java.util.MissingResourceException while accessing properties file 资源包中的java.util.MissingResourceException - java.util.MissingResourceException in Resource bundle ControlsFX 8.0.6对话框java.util.MissingResourceException - ControlsFX 8.0.6 dialogs java.util.MissingResourceException 运行jar时出现java.util.MissingResourceException - java.util.MissingResourceException when running a jar Vaadin国际化问题:java.util.MissingResourceException - Vaadin internationalization issue: java.util.MissingResourceException 加载 Java.properties 文件,获取 java.util.MissingResourceException:找不到基本名称的捆绑包我做错了什么? - Loading a Java .properties file, getting java.util.MissingResourceException: Can't find bundle for base name what am I doing wrong? java.util.MissingResourceException:找不到基本名称'property_file name'的捆绑包,语言环境en_US - java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US java.util.MissingResourceException-新File()不能进入jar-如何为外部库提供此File的路径? - java.util.MissingResourceException - new File() does not reach into jar - how to provide external library with a path for this File?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM