简体   繁体   中英

Property file in Tomcat\bin folder getting 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?

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 .


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"));
// ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM