您可以使用 ${variablename} 语法在 log4j 配置文件中使用系统属性。
您能否在其中也包含 Eclipse 变量(如项目名称)和 Maven 变量(如工件 ID),并在相应的构建过程中替换它们?
最佳答案
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?
对于后面的(Maven 变量),您可以使用 resources filtering 。通过添加 <filtering>
来激活它元素到您的 POM 并将其设置为 true
:
<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
</resources>
...
</build>
...
</project>
以及任何 Maven 属性,如 ${project.artifactId}
资源文件中使用的内容现在将被其值替换。您可以定义 includes
/excludes
以便更好地控制要过滤的资源。请参阅上面的链接以获取示例。
对于前者(Eclipse 变量),Maven 不知道它们,所以显然,这个解决方案不起作用,我实际上建议坚持使用 Maven 过滤(Maven 构建应该作为引用)。
如果您使用 m2eclipse,这将在 Eclipse 中透明地工作。
另请参阅
关于eclipse - 我可以将 Eclipse 和 Maven 变量替换到 log4j.properties 文件中吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3265250/