Java maven replacer插件和windows路径
我试图用maven build目录替换xml文件中硬编码的linux路径,以便在windows上进行测试,但是当我使用maven replacer插件的变量替换时,windows反斜杠路径分隔符会被删除。有办法解决这个问题吗 例如:Java maven replacer插件和windows路径,java,windows,maven,maven-replacer-plugin,Java,Windows,Maven,Maven Replacer Plugin,我试图用maven build目录替换xml文件中硬编码的linux路径,以便在windows上进行测试,但是当我使用maven replacer插件的变量替换时,windows反斜杠路径分隔符会被删除。有办法解决这个问题吗 例如: <plugin> <groupId>com.google.code.maven-replacer-plugin</groupId> <artifactId>replacer</ar
<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>
com.google.code.maven-replacer-plugin
替代者
准备包装
代替
我的档案
真的
/路径/到/替换
${project.build.directory}
结果是我得到了一个替换的值,比如“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>
com.google.code.maven-replacer-plugin
替代者
准备包装
代替
我的档案
真的
假的
/路径/到/替换
${project.build.directory}
请注意false
configuration属性。regex参数用于令牌匹配,对值没有影响。maven google replacer插件中有一个问题
要解决这个问题,您可以在将project.build.directory值传递给maven google replacer插件之前,先使用build helper maven插件撤销该值
这是一个编码解决方案:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>regex-property</id>
<phase>prepare-package</phase>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>cheminCible</name>
<value>${project.build.directory}</value>
<regex>\\</regex>
<replacement>/</replacement>
</configuration>
</execution>
</executions>
</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>cheminCible</value>
</replacement>
</replacements>
</configuration>
</plugin>
org.codehaus.mojo
构建助手maven插件
1.8
正则表达式属性
准备包装
正则表达式属性
化学战无不胜
${project.build.directory}
\\
/
com.google.code.maven-replacer-plugin
替代者
准备包装
代替
我的档案
真的
/路径/到/替换
化学战无不胜