my / src / test / resources中的log4j.properties不会覆盖main

时间:2013-07-23 13:08:47

标签: maven log4j

如何在测试期间让我的src/test/resources/log4j.properties文件覆盖我的/src/main/resources/log4j.properties?第一个结束于target/test-classes,第二个结束于target/classes

是的,我找了duplicates,但在这种情况下,我没有混合记录器 - 我正在使用 只有slf4j-log4j12。

2 个答案:

答案 0 :(得分:0)

你可以在pom.xml中使用maven配置文件和过滤以及maven-war-plugin。有了这个,您可以在log4j.properties中定义您需要的内容。

回溯示例:

在config.test.properties中定义变量:

basepath_log=/var/log/ProjectName

在logback.xml中定义占位符(相当于log4j.properties):

<appender>
...
    <file>${basepath_log}/ProjectName.log</file>
...
</appender>

个人资料定义:

<profiles>
        <profile>
            <id>test</id>
            <properties>
                <targetenv>test</targetenv>
            </properties>
        </profile>
</profiles>

过滤(pom.xml):

<filters>
    <filter>src/main/resources/filter/config.${targetenv}.properties</filter>
</filters>

然后,您可以使用选项-Ptest直接使用配置文件或在IDE中选择它(Netbeans,Eclipse ...)

答案 1 :(得分:0)

对不起,我的不好。 This bug建议我的问题可能是对坏版本的依赖。果然 - 2.3太旧了;更新版本的行为符合预期。

相关问题