简体   繁体   中英

Escape property in pom.xml

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.

$$使用${surefire.forkNumber}为我工作。

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>

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:

$&#8203;{somePomProperty}

This will be rendered as:

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

and will at least look correct.

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 \$ the literal backslash was carried through, and at no point was replaced with $.

YMMV I suppose.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM