Maven版本:3.5.4
我的 Web 目录不在标准位置。它位于/web
Maven war 配置
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<webResources>
<!--
Filter these files to look for ${my.maven.property} to replace them
at build time with a maven property value
-->
<resource>
<filtering>true</filtering>
<directory>web/WEB-INF</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>web</warSourceDirectory>
<failOnMissingWebXml>true</failOnMissingWebXml>
<webXml>web/WEB-INF/web.xml</webXml>
<packagingExcludes>
${exclude.files.on.build}
</packagingExcludes>
</configuration>
</plugin>
来自 pom.xml 的属性片段
<properties>
...
<!-- web.xml vars -->
<web.session.cookie.secure>true</web.session.cookie.secure> <!-- session cookie only sent over https -->
...
</properties>
web.xml 片段
<cookie-config>
...
<secure>${web.session.cookie.secure}</secure>
...
</cookie-config>
属性“${web.session.cookie.secure}”不会在 web.xml 中被替换,并且属性名称保留在生成的 war 文件中。我无法查明配置错误。我在 Intellij 中工作,无论是从 intellij 菜单构建 Artifact ,还是发出 mvn war:exploded 命令,都会得到相同的结果。
我假设它可能与 Web 目录位置和缺少的配置项有关。 Maven 构建按预期运行,但输出中的属性未被替换的问题除外。
关于为什么使用 maven-war-plugin 的过滤不会进行替换有什么想法吗?
最佳答案
maven-war-plugin
使用 ${basedir}
作为 pom 的位置,因此应该通过相对路径引用过滤的目标目录。
<resource>
<filtering>true</filtering>
<directory>${basedir}/web/WEB-INF</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
实际路径可以在mvn help: effective-pom
中检查。
关于java - Maven maven-war-plugin 不替换 web.xml 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53381173/