0

我正在使用 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 中是否需要额外的配置?(除了依赖)

先感谢您。

4

2 回答 2

2

Try to use

 InputStream is = this.getClass().getClassLoader().getResourceAsStream("log4j.properties");
于 2012-07-31T09:12:12.417 回答
1

你也可以试试这个:

PropertyConfigurator.configure(getClass().getResource("/<path if any>/log4j.properties"));
于 2012-07-31T09:28:07.440 回答