Log4j2 and maven - Picking wrong config file
I have two projects (P1 & P2) which are using Log4j2 logging. Each of the projects have their separate log4j2.xml placed in src/main/resources directory (according to maven structure).
The issue is, when I run any program in a project (say P1) through my IDE (Eclipse) it picks out the correct log4j2.xml. (May be because Eclipse resolves the classpath properly). But when I run the same program from command line, it picks out the log4j2.xml of project P2.
I have tried multiple time to "clean and install" the maven projects but to no help.
Generally it is a good idea to avoid putting config files inside jar files to avoid this exact problem. If you don't have a choice in the matter, you need to control the classpath such that the jar with the desired log4j2.xml precedes the jar with the undesired config file.
Also, you can specify the location of the config file with a system property: http://logging.apache.org/log4j/2.x/faq.html#config_location