使用maven-replacer-plugin在pom xml中使用html标签的正则表达式

时间:2013-09-13 14:20:58

标签: regex maven maven-2 pom.xml

我正在尝试使用maven-replacer-plugin找到并用pom.xml替换html标签。 使用当前配置,我收到错误消息“缺少结束标记地址”,这意味着pom没有转义打开标记<并关闭标记>

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.2</version>
    <executions>      
        <execution>
        <id>replace-script-reset-path-variable</id>
        <phase>prepare-package</phase>
        <goals>
            <goal>replace</goal>
        </goals>
        <configuration>
            <includes>
            <include>${basedir}/books/*.xml</include>
            </includes>
            <replacements>
                <replacement>
                    <token>/<(address)>/</token>
                    <value>/<(address)>//abc.com</value>
                </replacement>
            </replacements>                     
        </configuration>
        </execution>                        
    </executions>
</plugin>

目的是将源文件中包含html标记<address>的所有行替换为<address>abc.com/

以下是我的源文件示例:

<address>books/category/ebooks1/index.html</address>
<address>books/category/ebooks2/index.html</address>
<address>books/category/ebooks3/index.html</address>
<address>books/category/ebooks4/index.html</address>
<address>books/category/ebooks5/index.html</address>

应用正则表达式后,预期的源文件应为:

<address>abc.com/books/category/ebooks1/index.html</address>
<address>abc.com/books/category/ebooks2/index.html</address>
<address>abc.com/books/category/ebooks3/index.html</address>
<address>abc.com/books/category/ebooks4/index.html</address>
<address>abc.com/books/category/ebooks5/index.html</address>

2 个答案:

答案 0 :(得分:1)

您需要将实际POM文件中的<作为&lt;转义,同样适用于<

答案 1 :(得分:0)

我建议您使用令牌和值文件。在其中你可以简单地写这个:

<address>

<address>abc.com

然后您只需输入正确的文件路径即可。 E.g:

<tokenFile>resources/common/address-token.txt</tokenFile>
<valueFile>resources/common/address-value.txt</valueFile>

有关详细信息,请参阅Replacer usage guide