2014-04-01 78 views
0

我正在爲ant構建實現maven包裝。用於構建項目的ant命令如下使用maven執行帶有命名參數的shell腳本和ant腳本

ant -v -f build.xml -Darch=linux-java7 -Dconfig=/work/build.config -Doutput=/work/bldout/ 

現在我必須通過maven執行上述命令。我試圖用這個「I want to execute shell commands from maven's pom.xml」的實施和「http://sanchitbahal.wordpress.com/2011/09/19/maven-exec-plugin-vs-maven-antrun-plugin-for-running-command-line-tool/

示例代碼我想我的pom.xml裏面如下:

<plugin> 
     <artifactId>exec-maven-plugin</artifactId> 
     <groupId>org.codehaus.mojo</groupId> 
     <executions> 
      <execution> 
      <id>execute-shell</id> 
       <phase>compile</phase> 
       <goals> 
         <goal>exec</goal> 
       </goals> 
       <configuration> 
         <executable>test.sh</executable> 
         <arguments> 
          <argument>ARG1</argument> 
          <argument>ARG2</argument> 
         </arguments> 
      </configuration> 
      </execution> 
    </executions> 
</plugin> 

,但我無法弄清楚如何通過命名參數如 「-Darch = Linux的java7」 爲arguement到build.xml

也用於行家-antrun插件調用的build.xml如下:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 

    <executions> 
     <execution> 
      <id>run-target</id> 
      <phase>install</phase> 
       <configuration> 
       <target> 
        <ant antfile="build.xml" target="all" /> 
       </target> 
       </configuration> 
      <goals> 
      <goal>run</goal> 
      </goals> 
     </execution> 

但在這裏我也無法弄清楚如何傳遞參數,如「-Darch = linux-java7」作爲參數build.xml

我知道的是,我可以把命令放在shell腳本中一個.sh文件)並使用maven-exec-plugin調用shell腳本,但是想知道如果不這樣做,是否可以做到。

回答

0

使用antrun,它具有較少的外部依賴(像路等蟻可執行文件)由antrun插件執行

Ant任務繼承你的POM的properties節中定義的所有屬性。

所以你簡單的需要包括:

<properties> 
    <arch>linux-java7</arch> 
    ... 
</properties> 

您的POM內,使其工作。

+0

好的,會嘗試將它們添加到屬性標記中,您是否也知道如何通過pom傳遞-v和-f ant選項?當ant通過antrun插件執行時,這些選項是否真的有必要? – user2323134

+0

即使在從命令行調用時,'-f build.xml'也是不必要的,因爲缺省值是'build.xml'。 '-v'給出了詳細的輸出。恕我直言,沒有現成的選項可以用antrun做到這一點(除了使用'-X'打開整個maven作業的詳細信息之外,你真的需要'verbose'輸出嗎?verbose的想法是將額外的(調試)信息記錄在如果出現問題,這應該不是默認值。 – blackbuild

+0

好的,必須和我的隊友談論它,這是我第一次使用螞蟻,更好的是我必須先通過螞蟻。 – user2323134