2013-11-28 63 views
1

我試圖使Maven的Exec插件運行多個執行當調用下面的方式exec:java目標多次執行:但是在使用Maven 3.1.1我運行mvn exec:java的Maven Exec插件不工作

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2.1</version> 
      <executions> 
       <execution> 
        <id>first</id> 
        <goals> 
         <goal>java</goal> 
        </goals> 
        <configuration> 
         <mainClass>com.example.First</mainClass> 
        </configuration> 
       </execution> 
       <execution> 
        <id>second</id> 
        <goals> 
         <goal>java</goal> 
        </goals> 
        <configuration> 
         <mainClass>com.example.Second</mainClass> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

收到錯誤消息:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid -> [Help 1] 

運行exec:java目標爲單次執行(不使用嵌套executions元素)按預期工作。

回答

2

在我看來,問題是<execution/>都沒有綁定到特定的<phase/>。嘗試設置一個。

+0

如果我用「exec:java」明確地執行插件,哪一個階段應該是? – sakra

+0

那麼,如果你指定的'mainClass'是模塊源代碼的一部分,那麼你需要首先編譯代碼,所以最低限度是編譯,儘管我會推薦'package'運行測試。有關可能階段的詳細列表,請查看:http://maven.apache.org/ref/3.1.1/maven-core/lifecycles.html,以及http://maven.apache.org/guides/introduction/介紹到的,lifecycle.html。也許問題是,當你想運行exec目標時,這些類還沒有被編譯......? – carlspring

+0

另外我注意到,maven-exec-plugin不支持'java'目標的多個擴展。更多信息在這裏:http://stackoverflow.com/questions/22562558/the-maven-exec-plugin-executes-only-first-execution – victor