2012-07-31 27 views
0

我正在使用maven和log4j,但该应用程序无法加载在我的WAR文件中的“/”和“/ WEB-INF/classes /”中的log4j.properties。log4j.properties(没有这样的文件或目录)

在我的Java代码:

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

我需要在我的pom.xml额外的配置? (除了依赖)

谢谢你提前。

+0

如果是应用log4j属性把它放在src /测试/资源。它会自动拾取。为了在应用程序的容器中进行日志记录,我相信容器应该像jboss的log4j.xml一样指定配置 – 2012-07-31 09:13:10

回答

2

尝试使用

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

你可以试试这个还有:

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