Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 998
user673218 Avatar asked Jan 28 '26 09:01

user673218


1 Answers

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

like image 170
Remko Popma Avatar answered Jan 30 '26 22:01

Remko Popma