nybon nybon - 12 days ago 9
Java Question

log4j configuration file in a multi-module Maven project

I am working on a multi-module Maven project, whose structure is like this:

war-module
jar-module


The war-module depends on the jar-module, and will add the jar artifact into the webapp's lib directory after packaging.

And both the war-module and jar-module use Apache log4j for logging, and share the same log4j configuration file (log4j.xml), which locates in jar-module project at present. And this log4j.xml will be packaged into jar-module.jar file, however, I would like to make it into WEB-INF/classes directory in the war package rather than in the jar file so that users will be easy to find this configuration file and modify it if necessary (it is very hard for them to find it if this file is in the WEB-INF/lib/jar-module.jar because there are many other jars under that directory).

My question is: what is the Maven way to solve this problem?

Update:

My real project is a bit more complex, and there is a ear-module which depends on the jar-module too (aka. the jar-module can be used independently in several different projects, and I cannot just put the file into war-module/src/main/resources directory to fix this problem). And I don't want to duplicate some configuration files such as log4j.xml (and other configuration files such as myapp.properties) across the several projects.

Answer

I found the answer via some more searching on the web.

Generally, there are three ways to share resources in a multi module Maven project:

  • Cut and paste them.
  • Use Assembly and Dependency plugins
  • Use the maven-remote-resources-plugin

Here's a blog post from Sonatype, the company behind Maven, on sharing resources across projects in Maven, and it is the exact answer I need:

http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/