【问题标题】:How to ignore missing filter file error on pom.xml in Eclipse when using resource filtering?使用资源过滤时如何在 Eclipse 中忽略 pom.xml 上的丢失过滤器文件错误?
【发布时间】:2017-10-27 15:29:15
【问题描述】:

我有一个这样的多模块项目:

parent
|
+-- childA
|   +-- src/main/resources/application.properties
|
+-- childB
    +-- src/main/resources/application.properties
    +-- src/main/filters/filter.properties

我正在使用 childB 中的 filter.properties 过滤 childA 和 childB 中的 application.properties

我跟着this strategy将过滤器文件附加到childB的工件上,然后在childA的目标上解压:

childA/target/filters/filter.properties

childA 有这样的资源过滤:

<build>
  <filters>
    <filter>target/filters/filter.properties</filter>
  </filters>
</build>

Eclipse 在childA/pom.xml 上标记错误:

加载属性文件时出错 '父\childA\target\filters\filter.properties' (org.apache.maven.plugins:maven-resources-plugin:3.0.2:copy-resources:default-resources:process-resources)

过滤器文件在我构建应用程序时可用,所以我不关心那里。

如何更新 childA 的 pom.xml 以永久忽略此错误?

【问题讨论】:

    标签: java eclipse maven maven-3 maven-resources-plugin


    【解决方案1】:

    从 Eclipse Luna 升级到 Neon 后问题消失了。

    【讨论】:

      【解决方案2】:

      您已从 target 文件夹中获取了 filter.properties 文件。这不是正确的方法。你应该从你的考虑 src/main/filters/filter.properties 文件。

      <filters>
          <filter>${basedir}/src/main/filters/filter.properties</filter>
      </filters>
      

      更多内容,您可以阅读本教程:Error loading property file Maven

      更新#2:

      在我这边,您可以将属性文件保存在您的父级中。然后使用以下过滤器在 ChildA 和 childB 上提供参考。希望它会起作用。

      <filters>
          <filter>${basedir}/src/main/filters/filter.properties</filter>
      </filters>
      

      更新#3:

      Stephen conolly 在他的帖子中说如下:

      想想当您的项目被列为依赖项时会发生什么。 如果您通过使用 mojo 来指定其依赖项 从磁盘上的 .properties 文件,Maven 无法复制它 当您的依赖项已从 Maven 存储库中提取时。所以 Maven 将无法确定依赖关系。这样就可以 从不工作。

      您可以做的是使用外部系统(例如 ANT)生成 模板中的 pom.xml,其中版本被替换到该文件中。 然后使用实例化的模板进行构建。

      资源链接:https://stackoverflow.com/a/14727072

      在这里提出了类似的问题:Maven2 property that indicates the parent directory

      Dennis Lundbarg 在this post 中说这个问题是反模式:

      使用相对路径引用另一个模块中的文件是 反模式。这样做的一个原因是它会破坏你的构建,如果 您正在使用构建服务器,例如 Jenkins。构建服务器将 将每个模块签出到一个单独的文件夹中,该文件夹不在 与您的项目使用的文件夹结构相同。

      共享配置文件等资源的最佳实践方式是 将它们存储在部署到您的存储库的存档中。什么时候 完成后,您可以将其用作依赖项,从而使 类路径上可用的资源,或使用依赖项:解包 目标是将文件提取到您想要的任何位置。

      【讨论】:

      • 你是对的,但你误解了这个问题。 ChildA 需要 ChildB 资源中的 filter.properties 文件。澄清一下,附加 filter.properties 和解包的过程在 Maven 构建期间确实有效。问题在于 Eclipse 抛出的错误,这是一个误报。
      • 更新 #2 完全错误。文件仅在依赖项之间共享。我在 childA 和 childB 之间没有依赖关系。同样,实际的 Maven 构建过程正在运行。我的问题是 Eclipse 报告的错误。
      • 更新#3 更正了使用依赖和模块的相对路径是一种反模式。但是,我没有说我在使用相对路径。我将 filter.properties 附加到工件并在处理资源期间解包。
      猜你喜欢
      • 2012-07-25
      • 1970-01-01
      • 2013-08-11
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 2018-07-25
      • 2016-02-14
      • 2021-01-29
      相关资源
      最近更新 更多