首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用maven-replacer-plugin对pom xml中的html标记执行正则表达式

使用maven-replacer-plugin对pom xml中的html标记执行正则表达式
EN

Stack Overflow用户
提问于 2013-09-13 22:20:58
回答 2查看 2.3K关注 0票数 0

我正在尝试使用maven-replacer- pom.xml查找并替换html标记。使用当前的配置,我得到了一个错误,“缺少结束标签地址”,这意味着pom没有转义开放标签<和关闭标签>

代码语言:javascript
复制
<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>

目标是用<address>abc.com/替换源文件中具有html标记<address>的所有行

下面是我的源文件示例:

代码语言:javascript
复制
<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>

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

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

发布于 2013-09-13 22:29:41

您需要将实际POM文件中的<转义为&lt;,对于<也是如此,

票数 1
EN

Stack Overflow用户

发布于 2015-02-09 19:44:58

我建议您使用令牌和值文件。在它们中,您可以简单地编写以下代码:

代码语言:javascript
复制
<address>

代码语言:javascript
复制
<address>abc.com

然后您只需输入文件的正确路径。例如:

代码语言:javascript
复制
<tokenFile>resources/common/address-token.txt</tokenFile>
<valueFile>resources/common/address-value.txt</valueFile>

有关更多详细信息,请访问Replacer usage guide

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18788657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档