eclipse - 我可以将 Eclipse 和 Maven 变量替换到 log4j.properties 文件中吗?

标签 eclipse maven-2 configuration log4j variable-substitution

您可以使用 ${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/

相关文章:

eclipse - STS Eclipse 版本?

java - 如何在 Eclipse 中配置 Java -D 标志

java - Eclipse:查找方法的调用树

java - 如何找出需要哪些 jar ?

python - 如何在 PyCharm 中选择 Python 版本?

java - 如何在eclipse中链接项目

Android-Maven 安装时无法执行目标 org.codehaus.mojoto

java - 切换到旧版本的 Maven

c++ - 如何使用 Win32 API 从 INI 文件中删除一个部分?

java - 拦截器出错时如何将控件从拦截器重定向到jsp