2017-09-13 252 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(); 
相關問題