【发布时间】:2018-01-09 21:49:22
【问题描述】:
我在src/main/filters/base.properties 中有一个过滤器文件,内容如下:
testProperty=testValue
我的 POM 定义了资源、过滤和其他 Web 资源(使用 maven-war-plugin)。它还覆盖了默认的过滤分隔符。
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<filters>
<filter>src/main/filters/base.properties</filter>
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<overwrite>true</overwrite>
<useDefaultDelimiters>false</useDefaultDelimiters>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/more-web-resources</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
所有过滤都适用于位于src/main/resources 的文件。但是,位于src/main/more-web-resources 的配置文件没有被正确过滤。因此,如果我有一个文件src/main/more-web-resources/test.properties,其内容为:
finalTestProperty=@testProperty@
最终的src/main/webapp/test.properties 文件如下所示:
finalTestProperty=@testProperty@
相对于:
finalTestProperty=testValue
因此,过滤对使用 maven-war-plugin 指定的其他 Web 资源不起作用。我错过了什么?
【问题讨论】:
-
more-web-resources的内容可能应该在src/main/resources之下。 -
不是,它就是这样设计的。拥有另一个 Web 资源目录允许我直接在 Web 应用程序文件夹下使用更多文件来进行不同的构建配置。将它们放在
src/main/resources下意味着它们最终会在WEB-INF/classes下,这是我不想要的。我希望他们直接在 WAR 中。 -
过滤也在war插件的配置部分中配置。如果我没记错的话,pom 中的另一部分只是资源插件。插件文档中有一个很好的例子:maven.apache.org/plugins/maven-war-plugin/examples/…
-
尝试再定义另一个资源目录:
<resource><directory>src/main/more-web-resources</directory></resource> -
我真的必须在war插件配置中复制过滤器部分吗?我还使用 maven-properties-plugin 来拉入额外的过滤器文件,所以我看不出在插件内重新指定过滤器的情况下如何工作。
标签: java maven maven-war-plugin maven-resources-plugin