简体   繁体   中英

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.

Any ideas?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM