2014-04-01 111 views
0

我正在使用Maven 3.1.0。我有一個像這樣我可以讓Maven將文件轉換爲我可以在我的Maven腳本中使用的屬性嗎?

driver: com.mysql.jdbc.Driver 
url:  jdbc:mysql://localhost:3306/db 
username: user 
password: pass 

文件有沒有辦法,我可以得到Maven來解析這個文件,這樣就可以用在其他地方的按鍵(例如,「用戶名」)作爲屬性(如$ {用戶名})我的Maven腳本?最終,我想將這些屬性作爲連接參數傳遞給Maven SQL插件。

不幸的是,它沒有一個選項來改變這個文件的格式。

回答

0

看看在Properties Maven Plugin

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>properties-maven-plugin</artifactId> 
    <version>1.0-alpha-2</version> 
    <executions> 
     <execution> 
     <phase>initialize</phase> 
     <goals> 
      <goal>read-project-properties</goal> 
     </goals> 
     <configuration> 
      <files> 
      <file>myconfig.properties</file> 
      </files> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
</plugins> 

插件應該能夠處理你的屬性文件。如果不是(格式問題),則可以包含構建步驟以將文件轉換爲更方便的格式。

+0

順便說一句,我認爲你的鏈接因CodeHaus關閉而中斷。新的URL應該是:http://www.mojohaus.org/properties-maven-plugin/ – cbmeeks

+0

@cbmeeks更新,謝謝 – blackbuild

相關問題