I had a Java 8 project and my configuration file was in resource folder and everything worked fine. Now I switched to Java 9, added requirement for log4j.api
, and configuration file cannot be found anymore.
Do I need to add something else in my module-info
file for the logger to find it's config?
For now, it's like this
module project.main {
requires jdk.incubator.httpclient;
requires jackson.databind;
requires jackson.core;
requires jackson.annotations;
requires log4j.api;
}
The Project structure is as:
The build.gradle file is as:
The log4j~faq suggests using at least
log4j-api-2.x
andlog4j-core-2.x
. Preferably add these to yourbuild.gradle
file:And make sure conflicting dependencies are excluded
In the
module-info.java
further you shall update(this is what I did in a custom maven project)It should work for you then with the same directory structure as well.
Hint: This is where I started debugging it from. Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?
Placed a debug point in the
ClassLoader#getResource
method and just keep an eye of resources looked for by the library.Also to bring up the point over resources like
resources/foo/bar/log4j.properties
as stated in the release notes in JDK-8142968and seconded by the java-doc of
ClassLoader#getResource
as well: