java - Maven maven-war-plugin 不替换 web.xml 中的值

标签 java maven intellij-idea

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/

相关文章:

mongodb - 无法从 Intellij Idea ultimate/DataGrip 连接到 mongo atlas

java - Sonar 管 5.6 : violations reported for an outer class by findbugs is not reported as a sonar violation

java - 安卓 : How to ask permission to wireless?

Maven Mojo 映射复杂对象

java - 将 Dropbox 文件加载到 JList Maven Java NetBeans 中?

java - 没有找到给定的测试包括 : [***Test](filter. includeTestsMatching)

java - Android - 默认按钮样式

java - 如何在 JavaFX 舞台上创建自定义边框?

angularjs - OTS将Glyphicon的字体文件的: Failed to convert WOFF 2. 0字体错误解析为SFNT,用于Spring-boot

gradle - NoSuchMethodError - Intellij 和 lombok