`

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

    博客分类:
  • J2EE
 
阅读更多

详情请参考

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?

shareimprove this question
 
up vote5down voteaccepted

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

shareimprove this answer
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics