Maven - ERROR StatusLogger No log4j2 configuration file found
Solution 1
According http://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration adding log4j2.xml
to classpath should help.
If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
So if you still get ERROR message problem not with your sources. It looks like problem in maven-cucumber-reporting
plugin. As described here http://maven.apache.org/guides/mini/guide-maven-classloading.html
Please note that the plugin classloader does neither contain the dependencies of the current project nor its build output.
If maven plugin cannot find any log4j configuration in its own classpath (which is not including your sources/resources) you will see error messages. So yes, the only solution wait for release with fix https://github.com/damianszczepanik/cucumber-reporting/issues/675
Solution 2
You use the latest Cucumber version 3.15.0 (at the time of writing this). Your problem was resolved as issue #675. There was a commit from a pull request meant to fix this problem, but probably you have to wait until the next version is released in order to profit from it - or build a snapshot version locally and see if it also fixes the problem for you.
Solution 3
Run -> Run Configurations -> Classpath -> User entries -> Advanced Optiones -> Add Folders -> Then add your folder,in your case src/test/resources -> apply
It must work now :D
Solution 4
You are receiving this error because cucumber
or its dependencies are using log4j
for logging and since there is no log4j
configuration file so log4j
is printing such message.
If there is no log4j
configuration file, log4j
uses configuration similar to below -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configuration>
<Configuration status="warn" name="xml_configuration">
<Appenders>
<Console name="consoleLogger" target="SYSTEM_OUT">
<PatternLayout
pattern="[%level] %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="error" additivity="false">
<appender-ref ref="consoleLogger" />
</Root>
</Loggers>
</Configuration>
Adding above configuration in /src/main/resources/log4j2.xml
will have same result as having no log4j2.xml
file.
Another way to try is to pass log4j2.xml
file to maven directly without putting it in project classpath. Something like below -
set MAVEN_OPTS="-Dlog4j.configurationFile=file:///path/to/log4j2.xml"
mvn verify
silver
Updated on June 12, 2022Comments
-
silver almost 2 years
When running
mvn verify
I am getting below message:I already put the
log4j2.xml
undersrc/test/resources
(but not insrc/main/resources
because I do not want it to ship with actual app) as suggested here to no avail.The HTML report is generated, the log file is written, and the build is successful as seen above. I am unsure where the error is coming from.
-
Mr Cas about 6 yearsIs it the same message if you add the following dependency in the pom -> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.10.0</version> </dependency>
-
silver about 6 years@MrCas Still the same error message after adding
log4j-api
. After all, it is a transient dependency oflog4j-core
so it shouldn't matter whether it's specified in the pom.xml or not. -
Ivan about 6 yearshave you tried
-Dlog4j.configurationFile=file:///path/to/your/log4j2.xml
?
-
-
silver about 6 yearsThank you but this is a different logging framework.
-
silver about 6 yearsThank you but the src/test/resources is already marked as a source folder. Everything in it already goes to the target classpath.
-
silver about 6 yearsSorry I forgot about this bounty but this is impressive detective work. Acceptable explanation and marked as answer.
-
silver about 6 yearsHi, I do have the config file in the classpath. Turns out, this was a known defect in the
maven-cucumber-reporting
plugin itself that was not fixed until recently. -
kriegaex about 6 yearsWell, you can un-accept the other one and accept mine. My answer has been written 4 days before the accepted one and is correct. The other answer does not add value and even points to the very same ticket mine pointed to before. First come, first serve.