maven默认过滤器目录的好处 [英] Benefits of maven default filters directory
问题描述
最近我发现了maven资源过滤,并在文档中看到了一个注释:
Recently I have discovered maven resource filtering and saw one note in documentation:
标准目录布局 < br>
src / main / filters资源过滤器文件
Standard Directory Layout
src/main/filters Resource filter files
我注意到maven没有搜索在<$中声明的文件默认情况下,此目录中的c $ c>< filter> 标记。那么在这种情况下坚持使用Maven布局有什么好处(除了结构均匀性)?
I have noticed that maven does not search files declared in <filter>
tag in this directory by default. So what are the benefits of sticking with Maven Layout in this case (except structure uniformity ofcourse)?
推荐答案
基本上你假设 src / main / filters (或 src / test / filters )中存在的文件本身是可过滤的。这个假设是不正确的。
Basically you're assuming that the files that are present in src/main/filters (or src/test/filters) are themselves filterable. That assumption isn't correct.
src / main / filters 文件夹的目的是包含将使用的资源过滤器文件在过滤操作期间由Maven提供。
The purpose of the src/main/filters folder is to contain the resource filter files that will be used by Maven during the filtering action.
例如,假设您已定义以下属性:
For instance, imagine that you have the following property defined:
<project>
...
<properties>
<my.property>foo</my.property>
</properties>
...
</project>
现在想象你正在过滤一些文件夹:
And now imagine that you're filtering some folder:
...
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
使用该定义, src / main /中的任何文件包含 $ {my.property} 的资源将替换为 foo 。
现在想象一下每次要添加新属性时都不想更改POM。
Now imagine that you don't want to change your POM every time you want to add a new property.
然后是 src / main / filters 开始行动了。您可以使用属性在 src / main / filters 下创建一个文件,然后在POM中添加一个过滤器,而不是将您的属性放在POM中:
Then is when src/main/filters comes into action. Instead of placing your properties in your POM, you create a file under src/main/filters with your properties and you add a filter to your POM:
<project>
...
<name>Some Project</name>
...
<build>
...
<filters>
<filter>my-filter.properties</filter>
</filters>
...
</build>
...
</project>
这篇关于maven默认过滤器目录的好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!