2

I have a maven project with log4j2 (2.9.0) and a configuration file in /src/main/java/resources/log4j2.xml. As long as I stay in IntelliJ this works fine and it logs just like I configured it.

If I now make a mvn clean install in the terminal (Ubuntu 14) and then start the main method of my program in IntelliJ, I will get an error that it won't find the log4j2 configuration file:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.

As soon as I make Build -> Rebuild Project in IntelliJ IDEA it will work again.

I don't really understand how an external maven build could confuse IntelliJ IDEA to not take the .xml in the local source code.

Any idea?

1

1 Answer 1

3

I found the solution.

IntelliJ copies the resources per default to /target/classes and that's the place where IntelliJ actually takes the log4j2.xml from. My maven build didn't do that and IntelliJ didn't rebuild the project, so it couldn't find the log4j2.xml

My solution was to put the log4j2.xml in a resource section of the pom:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${project.build.directory}/classes</targetPath>
            <includes>
                <include>**/log4j2.xml</include>
            </includes>
        </resource>
    </resources>
2
  • In this case needed to override the default resources too, otherwise such premature override of resources might be the root causes of any other error that's rely on resources! Commented Jan 14, 2021 at 2:48
  • 1
    Better to close the IntelliJ Idea then remove metadata dir .idea & file *.iml. After that reopen IntelliJ Idea. It's solved the same issue! Commented Jan 15, 2021 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.