微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – maven-replacer-plugin和windows路径

我正在尝试使用maven构建目录替换xml文件中的硬编码linux路径,以便我可以在Windows上进行测试,但是当我使用maven-replacer-plugin的变量替换时,窗口反斜杠路径分隔符将被删除.有办法解决这个问题吗?

例如:

    <plugin>
      <groupId>com.google.code.maven-replacer-plugin</groupId>
      <artifactId>replacer</artifactId>
      <executions>
        <execution>
          <phase>prepare-package</phase>
          <goals>
            <goal>replace</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <filesToInclude>my_file</filesToInclude>
        <escape>true</escape>
        <replacements>
          <replacement>
            <token>/path/to/replace</token> 
            <value>${project.build.directory}</value>
          </replacement>
        </replacements>
      </configuration>
    </plugin>

结果是我获得了像“C:UsersPathNoSeparators”这样的替换值

有线索吗?

解决方法:

替换字符串中的反斜杠可能会导致它将其视为转义字符,因为替换是使用正则表达式完成的.

尝试将regex属性添加到false.

<plugin>
  <groupId>com.google.code.maven-replacer-plugin</groupId>
  <artifactId>replacer</artifactId>
  <executions>
    <execution>
      <phase>prepare-package</phase>
      <goals>
        <goal>replace</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <filesToInclude>my_file</filesToInclude>
    <escape>true</escape>
    <regex>false</regex>
    <replacements>
      <replacement>
        <token>/path/to/replace</token> 
        <value>${project.build.directory}</value>
      </replacement>
    </replacements>
  </configuration>
</plugin>

请注意< regex> false< / regex>配置属性.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐