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

发布于 2024-09-10 08:19:20 字数 123 浏览 2 评论 0原文

您可以使用 ${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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-09-17 08:19:20

您能否在其中也包含 Eclipse 变量(如项目名称)和 Maven 变量(如工件 ID),并在相应的构建过程中替换它们?

对于后者(Maven 变量),您可以使用 资源过滤。通过向 POM 添加 元素并将其设置为 true 来激活它:

<project>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

以及任何 Maven 属性,例如 ${project.artifactId} 在资源文件中使用的现在将被其值替换。您可以定义包含/排除以更好地控制要过滤的资源。请参阅上面的链接以获取示例。

对于前者(Eclipse 变量),Maven 不知道它们,所以显然,这个解决方案不起作用,我实际上建议坚持使用 Maven 过滤(Maven 构建应该是参考)。

如果您使用 m2eclipse,这将在 Eclipse 中透明地工作。

另请参阅

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文