如何配置Maven在不同环境中使用不同的log4j.properties文件 [英] How to configure maven to use different log4j.properties files in different environments

查看:472
本文介绍了如何配置Maven在不同环境中使用不同的log4j.properties文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够针对不同的环境使用不同的log4j配置.

I want to be able to use different log4j configuration for different environments.

在我的开发环境中,我想使用log4j.properties(A).但是,当我在Maven中为生产环境构建时,我想使用log4j.properties(B).

In my development environment, I want to use log4j.properties (A). But when I build in Maven for the production environment, I want to use log4j.properties (B).

请告诉我如何在pom.xml中进行配置?

Please tell me how to configure this in my pom.xml?

推荐答案

1. in your project add 3 folders : 

  Your Project\src\main\resources\

            \A > log4j.properties
            \B > log4j.properties
            \Default > log4j.properties
2. in pom.xml         

       <properties>
                <param>Default</param> 
        </properties>

        <build>
            <resources>
                <resource>
                    <directory>src/main/resources/${param}</directory>           
                </resource>
            </resources>
        </build> 

3. 

 - if : mvn clean install : classpath => log4j.properties(Default)

 - if : mvn clean install  -Dparam=A : classpath => log4j.properties(A)

 - if : mvn clean install  -Dparam=B : classpath => log4j.properties(B)


> much better than using profiles is more extensible without touching the pom

这篇关于如何配置Maven在不同环境中使用不同的log4j.properties文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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