2017-09-13 55 views
1

我有一个web应用程序作为Tomcat 6中的一个war进行部署。我试图从一个java类读取WEB-INF /下的一个配置文件打包在WEB-INF/lib下的jar文件中。我得到:系统找不到指定的文件 - 运行在Tomcat上的WEB-INF配置文件6

该系统找不到指定的文件

代码:

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)); 

它工作正常的服务器生产中,但在我们的测试服务器没有。它可以是服务器配置相关?

+0

您是否尝试过它没有反斜杠? – stdunbar

+0

是的,结果相同 – AGG

回答

0

试试这个:

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