简体   繁体   中英

log4j.properties in multiple maven modules?

What happens, when I have a maven application consisting of multiple modules and each of them contains a log4j.properties file, do they get merged or overwritten by a certain one (if yes, which one)?

Update: Following your advice I have now excluded the additional properties like this in my poms:

<dependency>
[...]
<excludes><exclude>**/log4j.properties</exclude></excludes>
</dependency>

PS: However, the "excludes" tag is not recognized by Maven and "exclusions" only works for dependencies, not resources.

Update

Just found out in log4j in a multi-module Maven project that I can just put the log4j.properties in src/test/resources so that they aren't included anyways in the executable module!.

They never get merged. Generally, the log4j.properties files get overwritten and you can not exactly tell which one.

It depends on the sequence of loading the Jar files by container.

So It is recommended to have one log4j.properties with multiple appenders each for other sub-modules in the core module of your application.

But it would create problem while testing/working with sub-modules independently as it will stop logging when tested separately. In our case, the source control version of pom always used to exclude resource (which will exclude the properties file while building the jar). However in developer local, developers used to comment that exclusion in POM and can work independently.

For example if you have 2 projects one for data and another for presentation. And both have the log4j.properties. And when you deploy the war file which also contains the data file inside it. Only the presentation project has the effect. And the log4.properties in the data project would be ignored. They will never get merged or over written by itself.

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