2011-10-13 288 views
4

我想在pom.xml中轉義屬性。不是在資源中,我知道可以使用過濾器。例如,我嘗試使用launch4j插件這樣的:pom.xml中的轉義屬性

<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必須不被行家進行解釋,而是由程序通過launch4j產生。 我嘗試:

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

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

,但沒有工作。

+0

根據[該線程](http://maven.40175.n5.nabble.com/escape-some-value-td122820.html),'$$ {ALLUSERSPROFILE}'應該工作。 –

+0

我看到了這個主題,但它不起作用 – EFalco

+0

發佈了一個完整的POM,它可以用於開箱即用,並重現錯誤。 – palacsint

回答

0

我加入時,我想通過與POM屬性值「$ {}的user.home」解決的關鍵「$ {} log4j.dir」過濾我log4j.properties文件相同的問題。

無論$$ {}鍵破解也不是$ {美元} {}鍵幫閒爲我工作。 我終於設法使用HEXA表示法來處理pom屬性中的$ char。

<project> 
    <properties> 
    <log4j.dir>\u0024{user.home}</log4j.dir> 
    </properties> 
    <!--...--> 
</project> 
-1

以下略從上面的線程修改爲我工作:

<properties> 
     <dollar>$</dollar> 
     <dollar.bloop>${dollar}{bloop}</dollar.bloop> 
    </properties> 
  • $$不被認可的IntelliJ。我真的希望編輯不要 有紅色的波浪。
  • 隨着\u0024字面反斜槓進行,並沒有被替換爲$。

情況因人而異,我想。

+0

不適用於Maven 3.5.0 –

0

對於真正的pom.xml你的運氣了逃逸。上述

一些答案提及Surefire插件,使用它自己的語法逃逸。這不是一回事。

的Maven資源過濾使用自己的機制來逃避。這不是一回事。

如果你僅僅需要打印的東西,你可以用zero-width-space unicode character,就像這樣:

$&#8203;{somePomProperty} 

這將呈現爲:

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

,將至少看起來是正確的。