【问题标题】:The system cannot find the file specified - WEB-INF config file running on Tomcat 6系统找不到指定的文件 - Tomcat 6 上运行的 WEB-INF 配置文件
【发布时间】:2017-09-13 21:16:10
【问题描述】:

我在 Tomcat 6 中部署了一个 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));

它在生产服务器中运行良好,但在我们的测试服务器中却不行。会不会是服务器配置相关?

【问题讨论】:

  • 你试过不加反斜线吗?
  • 是的,结果相同

标签: java web-applications tomcat6


【解决方案1】:

试试这个:

URL resource = new URL(this.getClass().getResource("."), "config.properties");
InputStream stream = resource.openConnection().getInputStream();

【讨论】:

    猜你喜欢
    • 2012-04-04
    • 2022-11-07
    • 1970-01-01
    • 2018-10-27
    • 2017-04-12
    • 2013-05-08
    • 2013-11-21
    • 2023-03-17
    相关资源
    最近更新 更多