我可以将 Eclipse 和 Maven 变量替换到 log4j.properties 文件中吗?
您可以使用 ${variablename} 语法在 log4j 配置文件中使用系统属性。
您是否可以在其中也包含 Eclipse 变量(如项目名称)和 Maven 变量(如工件 ID),并在相应的构建过程中替换它们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于后者(Maven 变量),您可以使用 资源过滤。通过向 POM 添加
元素并将其设置为true
来激活它:以及任何 Maven 属性,例如
${project.artifactId}
在资源文件中使用的现在将被其值替换。您可以定义包含
/排除
以更好地控制要过滤的资源。请参阅上面的链接以获取示例。对于前者(Eclipse 变量),Maven 不知道它们,所以显然,这个解决方案不起作用,我实际上建议坚持使用 Maven 过滤(Maven 构建应该是参考)。
如果您使用 m2eclipse,这将在 Eclipse 中透明地工作。
另请参阅
For the later (Maven variables), you can use resources filtering. Activate it by adding a
<filtering>
element to your POM and setting it totrue
:And any Maven property like
${project.artifactId}
used in a resource file will now get replaced by its value. You can defineincludes
/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