代码之家  ›  专栏  ›  技术社区  ›  Davio

检查Maven资源中的未解析属性

  •  3
  • Davio  · 技术社区  · 7 年前

    在src/main/resources/hello.xml中给定以下属性

    <test>${resolved.property}</test>
    <test>${unresolved.property}</test>
    

    resolved.property=test
    

    1 回复  |  直到 7 年前
        1
  •  1
  •   glytching    7 年前

    您可以使用 XML Maven Plugin 在资源筛选完成后验证XML文件。

    该插件可以根据模式验证XML文件,甚至只需检查其格式是否正确(这足以验证XML文件是否包含属性令牌)。

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>xml-maven-plugin</artifactId>
      <executions>
        <execution>
          <phase>process-resources</phase>
          <goals>
            <goal>validate</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <validationSets>
            <validationSet>
                <dir>... your xml dir ...</dir>
                <includes>
                    <include>*.xml</include>
                </includes>
            </validationSet>
        </validationSets>
      </configuration>
    </plugin>
    

    <phase>process-resources</phase> 这一点很重要,因为您希望确保验证运行 之后