arutaku arutaku - 2 months ago 18
Java Question

log4j.properties (No such file or directory)

I am using maven and log4j, but the app cannot load log4j.properties that is in "/" and "/WEB-INF/classes/" inside my WAR file.

In my Java code:

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


Do I need extra configuration in my pom.xml? (apart from the dependency)

Thank you in advance.

Answer Source

Try to use

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