我在 Tomcat 6 中部署了一个作为 war 的 Web 应用程序。我试图从打包在 WEB-INF/lib 下的 jar 中的 java 类读取 WEB-INF/下的配置文件。我得到:
系统找不到指定的文件
代码:
Properties props = new Properties();
File propsFile = new File(".\config.properties");
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(propertiesFilePath);
if (stream != null){
props.load(stream);
log.debug("stream not null");
}
else
props.load(new FileInputStream(propsFile));
它在生产服务器中运行良好,但在我们的测试服务器中则不然。可能与服务器配置有关?
最佳答案
试试这个:
URL resource = new URL(this.getClass().getResource("."), "config.properties");
InputStream stream = resource.openConnection().getInputStream();
关于java - 系统找不到指定的文件 - Tomcat 6 上运行的 WEB-INF 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46206962/