【问题标题】:How to filter with maven on only one property如何仅在一个属性上使用 Maven 进行过滤
【发布时间】:2013-06-18 18:51:53
【问题描述】:

我想通过 maven-war-plugin 仅在一个属性上使用 maven 进行过滤

我有属性:

  • key1=value1
  • key2=value2

还有一个文件:index.html

  • 你好 ${key1} - ${key2}

过滤后的实际结果:

  • 你好 value1 - value2

预期结果:我只想过滤属性“key1”

  • 你好 value1 - ${key2}

我的 pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>${project.basedir}/src/main/webapp</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>

请帮帮我。 谢谢你

【问题讨论】:

    标签: maven properties filter filtering war


    【解决方案1】:

    显而易见的方法是从属性文件中删除key2。如果这不是一个选项,过滤机制会提供一个 escapeString(在resources:resources goal docs 中了解更多信息)。默认情况下,这是一个反斜杠。

    index.html 文件将包含

    Hello ${key1} - \${key2}
    

    过滤应该产生

    Hello value1 - ${key2}
    

    我实际上并没有在 webResources 上尝试过这个,但我知道它适用于常规项目资源。

    【讨论】:

    • 我有一种情况,escapeString 和删除键都不是一个选项(无法控制过滤的文件)。这是过滤系统的一个非常糟糕的限制。
    猜你喜欢
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    相关资源
    最近更新 更多