Can I substitute Eclipse and Maven variables into a log4j.properties file?
You ca开发者_运维知识库n 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?
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
- How do I filter resource files?
- Chapter 9. Properties and Resource Filtering
- MavenPropertiesGuide
精彩评论