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>配置属性.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...