2012-02-17 45 views
5

是否可以讀取文件並將整個內容存儲到Maven屬性中?將文件讀入Maven屬性

我想要生成一些自定義的JavaDocs,他們有一個選項來設置一個頭,但它必須是一個字符串,而不是文件名(出於某種原因)。我顯然不想將一堆HTML放到我的pom.xml中,所以我需要一種方法將我的header.html作爲Maven屬性來讀取。

這可能嗎?我無法找到一個標準的方式,但它看起來像一個Maven插件可能會這樣做。

顯然Ant has what I want,但我更喜歡比Ant任務重量更輕的東西。

+0

Brendan,做了解決方案的工作?我沒有機會親自嘗試。 – 2012-02-22 05:37:27

回答

9

請參閱this關於SO的問題。這裏是properties-maven-plugin

如果您想不使用的.properties文件,不是我可以建議使用Groovy插件和我寫了一個小腳本:

<plugin> 
    <groupId>org.codehaus.gmaven</groupId> 
    <artifactId>gmaven-plugin</artifactId> 
    <version>1.4</version> 
    <executions> 
    <execution> 
     <phase>generate-resources</phase> 
     <goals> 
     <goal>execute</goal> 
     </goals> 
     <configuration> 
     <properties> 
      <header_file>header.html</header_file> 
     </properties> 
     <source> 
      def file = new File(project.properties.header_file) 
      project.properties.header_content = file.getText() 
     </source> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

這個插件執行後,你應該能夠參考${header_content}財產,其中包含header.html文件內容。

+0

如果您需要閱讀pom文件中的屬性,這不起作用 – 2015-01-05 15:21:09