在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

 

Can I substitute Eclipse and Maven variables into a log4j.properties file?

up vote 4 down vote favorite
2

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

active oldest votes
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 element to your POM and setting it to true:


  ...
  
    ...
    src/main/resourcestrue
      ...
    
    ...
  
  ...

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

  • How do I filter resource files?
  • Chapter 9. Properties and Resource Filtering
  • MavenPropertiesGuide
share improve this answer

你可能感兴趣的:(J2EE)