使用资源过滤时,如何在 Eclipse 中忽略 pom.xml 上丢失的过滤文件错误?
How to ignore missing filter file error on pom.xml in Eclipse when using resource filtering?
我有一个这样的多模块项目:
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
:
上标记错误
Error loading property file
'parent\childA\target\filters\filter.properties'
(org.apache.maven.plugins:maven-resources-plugin:3.0.2:copy-resources:default-resources:process-resources)
过滤器文件在我构建应用程序时可用,所以我不关心那里。
如何更新 childA 的 pom.xml 以永久忽略此错误?
您已从 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 在他的 post 中讲述如下:
Think about what happens when your project is listed as a dependency.
If you had specified its dependencies by using a mojo to pull those
from a .properties file on disk, Maven has no way to replicate that
when your dependency has been pulled from the Maven repository. So
Maven would be unable to determine the dependencies. Thus it could
never work.
What you could do, is use an external system (e.g. ANT) to generate
the pom.xml from a template with the versions replaced into that file.
And then use the instantiated template to build.
资源 Link:
这里问了类似的问题:Maven2 property that indicates the parent directory
Dennis Lundbarg 在 this post 中将此问题称为反模式:
Referencing a files in another module using relative paths is an
anti-pattern. One reason for this is that it will break your build if
you are using a build server, like Jenkins. The build server will
check out each module into a separate folder, which is not in the
same folder structure that your project is using.
The best practice way of sharing resources like configuration files is
storing them in an archive that is deployed to your repository. When
that is done you can either use it as a dependency, making the
resources available on the class path, or use the dependency:unpack
goal to extract the files to wherever you want them.
从 Eclipse Luna 升级到 Neon 后问题消失了。
我有一个这样的多模块项目:
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
:
Error loading property file 'parent\childA\target\filters\filter.properties' (org.apache.maven.plugins:maven-resources-plugin:3.0.2:copy-resources:default-resources:process-resources)
过滤器文件在我构建应用程序时可用,所以我不关心那里。
如何更新 childA 的 pom.xml 以永久忽略此错误?
您已从 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 在他的 post 中讲述如下:
Think about what happens when your project is listed as a dependency. If you had specified its dependencies by using a mojo to pull those from a .properties file on disk, Maven has no way to replicate that when your dependency has been pulled from the Maven repository. So Maven would be unable to determine the dependencies. Thus it could never work.
What you could do, is use an external system (e.g. ANT) to generate the pom.xml from a template with the versions replaced into that file. And then use the instantiated template to build.
资源 Link:
这里问了类似的问题:Maven2 property that indicates the parent directory
Dennis Lundbarg 在 this post 中将此问题称为反模式:
Referencing a files in another module using relative paths is an anti-pattern. One reason for this is that it will break your build if you are using a build server, like Jenkins. The build server will check out each module into a separate folder, which is not in the same folder structure that your project is using.
The best practice way of sharing resources like configuration files is storing them in an archive that is deployed to your repository. When that is done you can either use it as a dependency, making the resources available on the class path, or use the dependency:unpack goal to extract the files to wherever you want them.
从 Eclipse Luna 升级到 Neon 后问题消失了。