Maven程序集插件:当冒号存在时,过滤器不会转义反斜杠

时间:2013-02-20 15:22:21

标签: maven-assembly-plugin

我正在使用Maven程序集插件2.4过滤一些配置文件,并且遇到的问题是,在.bat文件中,当值包含冒号时,文字反斜杠不会被转义。

的pom.xml:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <filters>
      <filter>src/assembly/filter.properties</filter>
    </filters>
    <descriptors>
      <descriptor>src/assembly/assembly.xml</descriptor>
    </descriptors>
  </configuration>
</plugin>

filter.properties:

#Double (escaped) backslashes
testPath1 = a\\b\\c
testPath2 = c:\\test
#testPath3 contains no colon
testPath3 = c\\test

test.bat的:

REM ${testPath1}
REM ${testPath2}
REM ${testPath3}

test.properties:

path1=${testPath1}
path2=${testPath2}
path3=${testPath3}

assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>distribution</id>
  <formats><format>zip</format></formats>
  <files>
    <file>
      <source>${basedir}/src/assembly/testBat.bat</source>
      <outputDirectory>/</outputDirectory>
      <filtered>true</filtered>
    </file>
    <file>
      <source>${basedir}/src/assembly/testProp.properties</source>
      <outputDirectory>/</outputDirectory>
      <filtered>true</filtered>
    </file>
  </files>
</assembly>

这就产生了......

testBat.bat(所有反斜杠都被转义):

REM a\b\c
REM c:\test\path
REM c\test\path

testProp.properties(path2中的反斜杠未按预期转义!!!):

path1=a\b\c
path2=c:\\test\\path
path3=c\test\path

任何人都知道这是某种特殊功能,还是实际上是一个错误? :)

1 个答案:

答案 0 :(得分:0)

就像更新一样,我现在正在使用Ant的过滤器功能而不是Maven程序集插件的过滤功能。最初我想用Maven创建特定于环境的工件,但是,由于环境略有不同,决定只使用Maven构建一个交付包,然后在部署时让Ant脚本填充配置模板。