多模块Maven项目中的log4j配置文件 [英] log4j configuration file in a multi-module Maven project

查看:1379
本文介绍了多模块Maven项目中的log4j配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个多模块Maven项目,其结构如下:

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

war-module
jar-module

war-module依赖于jar模块,并会添加jar工件打包后进入webapp的lib目录。

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

war-module和jar-module都使用Apache log4j进行日志记录,并共享相同的log4j配置文件(log4j.xml) ),目前位于jar模块项目中。并且这个log4j.xml将被打包到jar-module.jar文件中,但是,我想把它放到war包中的WEB-INF / classes目录而不是jar文件中,以便用户很容易找到这个配置文件并在必要时进行修改(如果此文件位于WEB-INF / lib / jar-module.jar中,则很难找到它,因为该目录下有许多其他jar)。

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).

我的问题是:Maven解决这个问题的方法是什么?

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

更新:

我真正的项目有点复杂,而且还有一个依赖于jar模块的ear-module(也就是jar模块可以可以在几个不同的项目中独立使用,我不能只将文件放入war-module / src / main / resources目录来解决这个问题)。而且我不想在几个项目中复制一些配置文件,例如log4j.xml(以及其他配置文件,例如myapp.properties)。

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.

推荐答案

我通过网上搜索找到了答案。

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

通常,有三种方法可以在多模块Maven项目中共享资源:

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



  • 剪切并粘贴它们。

  • 使用汇编和依赖项插件

  • 使用maven-remote-resources-插件

以下是来自Maven背后的公司Sonatype的博客文章,内容涉及跨项目共享资源Maven,这是我需要的确切答案:

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 /

这篇关于多模块Maven项目中的log4j配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆