2012-11-29 72 views

回答

8

這裏是我做過什麼:

使用antrun插件創建它與列表中的臨時文件:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7</version> 
    <executions> 
     <execution> 
      <phase>generate-sources</phase> 
      <configuration> 
       <target> 
        <fileset id="my-fileset" dir="src/main/resources" /> 
        <pathconvert targetos="unix" pathsep="," 
         property="my-file-list" refid="my-fileset"> 
         <map from="${basedir}\src\main\resources\" to="" /> 
        </pathconvert> 
        <echo file="${basedir}\target\file-list.txt">${my-file-list}</echo> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

然後使用替代品的插件我替換名單我想要的文件:

<plugin> 
    <groupId>com.google.code.maven-replacer-plugin</groupId> 
    <artifactId>maven-replacer-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>replace-file-list</id> 
      <phase>prepare-package</phase> 
      <goals> 
       <goal>replace</goal> 
      </goals> 
      <configuration> 
       <ignoreMissingFile>false</ignoreMissingFile> 
       <file>target/MY_FILE.TXT</file> 
       <regex>false</regex> 
       <token>$file-list$</token> 
       <valueFile>target/file-list.txt</valueFile> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

我確定必須有一個bett呃方式,但希望這有助於某人。

+0

本頁建議「正確」的方式並不是更漂亮:https://maven.apache.org/plugin-developers/cookbook/add-build-time-to-manifest.html –

相關問題