2014-02-18 133 views
0

我有一個.bat文件,它執行我的Maven項目的構建的一些先決條件,並且我想在我開發的項目被構建時自動執行這個.bat文件。有沒有辦法從maven配置執行批處理文件?

有什麼辦法可以用Maven執行這個任務嗎?

我看到了另一個類似的問題,但它並沒有解決我的問題。

+0

可能重複:http://stackoverflow.com/questions/3491937/i-want-to-execute-shell-commands-from-mavens- pom-xml –

+0

我個人建議避免這樣做。調用shell腳本使得maven構建不可移植。學習寫一點MOJO,或切換到其他構建工具。 –

+4

你可以使用'maven-antrun-plugin'並用ANT執行.bat文件。 – whyem

回答

2

執行批處理文件作爲Maven構建過程的一部分的最直接和靈活的方法是使用maven-antrun-pluginexec任務。例如,考慮下面的代碼運行一個Windows可執行文件:

 <!-- in the <build> section --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>sign</id> 
        <phase>package</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <tasks> 
          <exec executable="${env.WIN7BASE}\bin\selfsign\inf2cat.exe"> 
           <arg line="/drv:${project.build.directory}\classes /os:Vista_X86" /> 
          </exec> 
          <exec executable="${signtool}"> 
           <arg line="sign /v /a /t http://timestamp.verisign.com/scripts/timestamp.dll ${project.build.directory}\classes\${project.name}.cat" /> 
          </exec> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
相關問題