1

我正在使用 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>

过滤器属性:

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

测试.bat:

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

测试属性:

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

程序集.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

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

4

1 回答 1

0

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

于 2013-12-06T08:50:40.057 回答