【问题标题】:Change the value of specific tag in xml file using maven使用maven更改xml文件中特定标签的值
【发布时间】:2020-10-20 03:50:52
【问题描述】:

我的 xml 文件中有以下标记

<sequence name="Producers_Codes_In" onError="Producers_Fault" trace="disable" xmlns="http://ws.apache.org/ns/synapse">

我想将属性 name="Producers_Codes_In" 替换为 name="Producers_Codes_In-1.0.0"。这与maven有关。 实际上可以通过这种方式使用maven-antrun-plugin重命名项目工件中的属性

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
      <execution>
        <id>artifacts_version</id>
        <phase>validate</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
            <replaceregexp byline="true">
              <regexp pattern="version=&quot;(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)?(?:(\d+)\.)?(\*|\d+)(-SNAPSHOT)?&quot;" />
              <substitution expression=" version=&quot;${project.version}&quot;" />
              <fileset dir=".">
                <include name="artifact.xml" />
              </fileset>
            </replaceregexp>
          </tasks>
        </configuration>
      </execution>
    </executions>
  </plugin>

当我指定要更改的文件时,问题就来了。 非常感谢您的帮助!

【问题讨论】:

    标签: maven plugins compilation wso2 pom.xml


    【解决方案1】:

    我找到了答案。覆盖所有文件的关键是属性 --> flag="g" 就像在这个例子中

    <replaceregexp 
        match=" context=&quot;/producers/(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)?(?:(\d+)\.)?(\*|\d+)&quot;"
        replace=" context=&quot;/producers/${project.version}&quot;" 
        flags="g" 
        byline="true">
           <fileset dir="." includes="**/*.xml" />
        </replaceregexp>
    

    更多信息请访问此页面https://ant.apache.org/manual/Tasks/replaceregexp.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多