问题
I would like to escape a property in pom.xml. Not in ressources, I know it is possible with a filter. For example I try to use launch4j plugin like this :
<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>
And ${ALLUSERSPROFILE} must not be interpreted by maven but by the program generate by launch4j. I try :
\${ALLUSERSPROFILE}
\\${ALLUSERSPROFILE}
$${ALLUSERSPROFILE}
and
<properties>
<dollar>$</dollar>
</properties>
${dollar}{ALLUSERSPROFILE}
but nothing work.
回答1:
$$
worked for me with ${surefire.forkNumber}.
回答2:
I add the same issue when I wanted to filter my log4j.properties file by resolving the key '${log4j.dir}' with the pom property value '${user.home}'.
Neither $${key} hack nor ${dollar}{key} hack worked for me. I finally managed to do it using the HEXA notation for the $ char in the pom property.
<project>
<properties>
<log4j.dir>\u0024{user.home}</log4j.dir>
</properties>
<!--...-->
</project>
回答3:
For true escaping in a pom.xml
you are out of luck.
Some answers above make reference to the Surefire plugin, which uses its own syntax for escaping. That's not the same thing.
Maven resource filtering uses its own mechanism for escaping. That's not the same thing.
If you merely need to print something, you can use the zero-width-space unicode character, like this:
$​{somePomProperty}
This will be rendered as:
$ + zero-width-space + { + somePomProperty + }
and will at least look correct.
回答4:
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.
来源:https://stackoverflow.com/questions/7751696/escape-property-in-pom-xml