簡體   English   中英

log4j.properties(無此文件或目錄)

[英]log4j.properties (No such file or directory)

我正在使用maven和log4j,但是應用程序無法加載WAR文件中“ /”和“ / WEB-INF / classes /”中的log4j.properties。

在我的Java代碼中:

try {
    Properties props = new Properties();
    props.load(new FileInputStream("log4j.properties"));
    PropertyConfigurator.configure(props);
} catch (Exception e) {
    ...
}

我的pom.xml是否需要額外的配置? (除了依賴項)

先感謝您。

嘗試使用

 InputStream is = this.getClass().getClassLoader().getResourceAsStream("log4j.properties");

您也可以嘗試以下方法:

PropertyConfigurator.configure(getClass().getResource("/<path if any>/log4j.properties"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM