在log4j.properties中使用maven的properites变量

详情请参考

http://stackoverflow.com/questions/3265250/can-i-substitute-eclipse-and-maven-variables-into-a-log4j-properties-file

 

http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

 

http://www.coderanch.com/t/107838/tools/variable-substitution-log-properties-file

 

You can use system properties in log4j configuration files using a ${variablename} syntax.

Can you include Eclipse variables (like the project name) and Maven variables (like the artifact ID) in there too, and have them substituted during the respective build?

share improve this question
 

1 Answer

up vote 5 down vote accepted

Can you include Eclipse variables (like the project name) and Maven variables (like the artifact ID) in there too, and have them substituted during the respective build?

For the later (Maven variables), you can use resources filtering. Activate it by adding a <filtering>element to your POM and setting it to true:

<project>
  ...
  <build>
    ...
    <resources><resource><directory>src/main/resources</directory><filtering>true</filtering></resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

And any Maven property like ${project.artifactId} used in a resource file will now get replaced by its value. You can define includes/excludes for finer control of resources that you want to filter. Refer to the above link for examples.

For the former (Eclipse variables), Maven is not aware of them so, obviously, this solution won't work and I actually suggest sticking to Maven filtering (the Maven build should be the reference).

If you are using m2eclipse, this will work transparently inside Eclipse.

See also

share improve this answer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值