5

我想转义 pom.xml 中的属性。不在资源中,我知道可以使用过滤器。例如,我尝试像这样使用 launch4j 插件:

<plugin>
<groupId>org.bluestemsoftware.open.maven.plugin</groupId>
            <artifactId>launch4j-plugin</artifactId>
                <executions>
                    <execution>
                        <id>l4j-cli</id>
                        <phase>install</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <outfile>../out.exe</outfile>
                            <dontWrapJar>true</dontWrapJar>
                            <jar>./../out.jar</jar>
                            <icon>../icon.ico</icon>
                            <chdir>.</chdir>
                            <customProcName>true</customProcName>
                            <downloadUrl>http://www.oracle.com/technetwork/java/javase/downloads/index.html</downloadUrl>
                            <classPath>
                                <mainClass>com.stack.Main</mainClass>
                                <addDependencies>true</addDependencies>
                                <jarLocation>./lib</jarLocation>
                            </classPath>
                            <jre>
                                <opts>
                                    <opt>-DconfigBasePath=${ALLUSERSPROFILE}/dir</opt>
       </opts>                          
                            </jre>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

并且 ${ALLUSERSPROFILE} 不能由 maven 解释,而是由 launch4j 生成的程序解释。我尝试:

\${ALLUSERSPROFILE}
\\${ALLUSERSPROFILE}
$${ALLUSERSPROFILE}

<properties>
   <dollar>$</dollar>
</properties>
${dollar}{ALLUSERSPROFILE}

但没有任何工作。

4

4 回答 4

1

$$为我工作${surefire.forkNumber}

于 2013-12-12T20:21:25.517 回答
0

当我想通过使用 pom 属性值'${user.home}'解析键'${log4j.dir}'来过滤我的log4j.properties文件时,我添加了相同的问题。

$${key} hack 和 ${dollar}{key} hack 都不适合我。我终于设法对 pom 属性中的 $ char 使用 HEXA 表示法来做到这一点。

<project>
    <properties>
    <log4j.dir>\u0024{user.home}</log4j.dir>
    </properties>
    <!--...-->
</project>
于 2012-12-18T10:16:45.587 回答
0

对于真正的逃避,pom.xml你不走运。

上面的一些答案引用了 Surefire 插件,它使用自己的语法进行转义。那不是一回事。

Maven 资源过滤使用自己的转义机制。那不是一回事。

如果你只需要打印一些东西,你可以使用zero-width-space unicode character,像这样:

$&#8203;{somePomProperty}

这将呈现为:

$ + zero-width-space + { + somePomProperty + }

并且至少看起来是正确的。

于 2017-09-22T17:31:34.430 回答
-1

The following slightly modified from the above thread worked for me:

    <properties> 
      <dollar>$</dollar> 
      <dollar.bloop>${dollar}{bloop}</dollar.bloop> 
    </properties> 
  • $$ was not recognised by IntelliJ. I really want the editor to not have red squiggles.
  • With \u0024 the literal backslash was carried through, and at no point was replaced with $.

YMMV I suppose.

于 2015-05-02T10:50:24.753 回答