开发者

Escape property in pom.xml

开发者 https://www.devze.com 2023-04-12 22:18 出处:网络
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 :

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>
                  开发者_如何学Python      </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.


$$ worked for me with ${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>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号