【问题标题】:Maven maven-replacer-plugin Issue, in removal of the braces after the replace is doneMaven maven-replacer-plugin 问题,在替换完成后移除大括号
【发布时间】:2015-07-15 11:51:21
【问题描述】:

我正在使用 maven-replacer-plugin (https://code.google.com/p/maven-replacer-plugin/wiki/UsageGuide)。 我正在使用用例解释“使用 tokenValueMap 替换单个文件”。

我无法在具有这些标记的源文件中正确替换标记。

要求 我需要生成一个 XML 文件,其中包含令牌的字段值,取自属性文件。

XML 文件,格式如下。

XML_DEV.txt

 <field>
     <name>HTTP/Server</name>
     <value>${Server}</value>
 </field>
 <field>
     <name>HTTP/Port</name>
     <value>${Port}</value>
 </field>

我在每个环境(DEV、QA、PROD)的单独属性文件中定义了这些占位符变量(服务器和端口)的值。

Application_DEV.properties

Server=DEV_Application_Server1
Port=8081

Application_QA.properties

Server=QA_Application_Server11
Port=8082

我正在使用 ${..} 来识别源 XML 文件 (XML_DEV.txt) 中的标记。 我正在使用 tokenValueMap 来识别标记列表以及需要为这些标记替换的值。

到目前为止发生了什么......

我能够替换值,但在生成的输出文件中没有删除 ${} 大括号。 QA 替换示例。 输入(来自文件 XML_DEV.txt 的示例)

 <field>
     <name>HTTP/Server</name>    
     <value>${Server}</value>
 </field>

正在更改为

输出(来自文件 XML_DEV_mod.txt 的示例)

 <field>
     <name>HTTP/Server</name>
     <value>${QA_Application_Server11}</value>
 </field>

所有标记都已更改,但 '${ }' 仍然存在于上述输出文件中。 我使用的 POM 文件如下。如果我遗漏了什么,请告诉我,以强制 Maven 删除 ${ }。

我当前的 POM 文件

<build>
    <plugins>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
            <executions>                
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>                    
                </execution>
            </executions>
            <configuration>
                <file>${inputFile}</file>
                <tokenValueMap>DEV_properties.txt</tokenValueMap>
                <outputFile>${outFileName}</outputFile>
            </configuration>
        </plugin>
    </plugins>
</build>

DEV_properties.txt(代币价值图)

Server=DEV_Application_Server1
Port=8081
inputFile=XML_DEV.txt
outFileName=XML_DEV_mod.txt

感谢您对此的帮助。

提前致谢

-拉古

PS: 我之前有一篇关于这个问题的帖子(查询),建议我使用过滤来解决这个要求。 当我找到这个替换插件来替换令牌时,我仍在研究过滤器选项(尽管到目前为止我还没有成功)。

Maven - Solution to replace variables in a XML file after fetching their values from a properties file

【问题讨论】:

    标签: maven replace


    【解决方案1】:

    更新, 我能够通过使用&lt;delimiters&gt; 来解决问题,当我使用% 作为令牌时,如下所示。

    <build>
        <plugins>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
            <executions>                
            <execution>
                <phase>prepare-package</phase>
                <goals>
                <goal>replace</goal>
                </goals>                    
            </execution>
            </executions>
            <configuration>
            <delimiters>
              <delimiter>%</delimiter> 
            </delimiters>
            <file>${inputFile}</file>
            <tokenValueMap>DEV_properties.txt</tokenValueMap>
            <outputFile>${outFileName}</outputFile>
            </configuration>
        </plugin>
        </plugins>
    </build>
    

    这可能会更改包含以下标记的输入文件

     <field>
         <name>HTTP/Server</name>    
         <value>%Server%</value>
     </field>
    

     <field>
         <name>HTTP/Server</name>
         <value>QA_Application_Server11</value>
     </field>
    

    根据需要。

    我希望${Var} 像问题中提到的那样进行更改。 但这解决了需求。

    感谢下面的帖子, Managing Google Maps API keys

    问候

    -拉古

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2011-05-30
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      相关资源
      最近更新 更多