2011-12-14 77 views
1

我正在使用maven-properties-plugin將我的屬性寫入文件以供第三方應用程序使用。Maven - pom中屬性名稱中的特殊字符

我想在屬性名稱中包含一個特殊字符'$'。

例如:

<properties> 
<a$Boolean>SOMETHING</a$Boolean> 
... 

我沒能找到一個轉義字符。

我將不勝感激解決方案。

謝謝, Ika。

+0

爲什麼你需要這樣的要求。爲什麼`aBoolean`或`a-Boolean`不夠? – 2011-12-14 11:49:13

+0

因爲使用輸出屬性文件的軟件在變量名稱中使用$作爲分隔符。 – Ika 2011-12-14 13:10:31

回答

2

$是$的轉義字符。

只是把它兩次,例如,

<properties> 
    <prop-with-dollar>Prop-with-$$</prop-with-dollar> 
</properties> 

prop-with-dollar值將是Prop-with-$

編輯

更仔細閱讀後,意識到真正的問題是關於$在屬性名。

它在Maven中不受支持。這不是不合理的。許多語言僅支持變量名稱的有限字符集。例如,在Java $!<>-和許多其他字符不能出現在變量名稱中。

0

我最後做的是通過在每一個我所需要的美元符號的地方寫「DOLAR」,然後替換的所有實例「DOLAR用‘$’ 這裏使用maven replacer plugin是一個代碼示例:

<plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>properties-maven-plugin</artifactId> 
     <version>1.0-alpha-2</version> 
     <executions> 
      <execution> 
      <id>Generating varfile for the install4j</id> 
      <phase>generate-resources</phase> 
      <goals> 
       <goal>write-active-profile-properties</goal> 
      </goals> 
      <configuration> 
       <outputFile>C:\Dev\out.varfile</outputFile> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <groupId>com.google.code.maven-replacer-plugin</groupId> 
     <artifactId>maven-replacer-plugin</artifactId> 
     <version>1.4.0</version> 
     <executions> 
      <execution> 
      <id>Replacing the DOLAR sign with real dollar sign in varfile</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>replace</goal> 
      </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <basedir>C:\Dev\</basedir> 
      <file>out.varfile</file> 
      <replacements> 
      <replacement> 
       <token>DOLAR</token> 
       <value>\$$</value> 
      </replacement> 
      </replacements> 
     </configuration> 
     </plugin> 
0

能爲你工作,這是值得嘗試這樣的:

<project> 
    <properties> 
     <a\u0024Boolean>SOMETHING</a\u0024Boolean> 
    </properties> 
    <!--...--> 
</project> 

我添加了同樣的問題時,我想通過解決關鍵過濾我log4j.properties文件'$ {log4j.dir}'與pom屬性值'$ {user.home}'

$$ {key} hack和$ {dollar} {key} hack都不適合我。 我終於設法使用HEXA表示法來處理pom屬性中的$ char。

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

祝你好運!