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
元素)按預期工作。
如果我用「exec:java」明確地執行插件,哪一個階段應該是? – sakra
那麼,如果你指定的'mainClass'是模塊源代碼的一部分,那麼你需要首先編譯代碼,所以最低限度是編譯,儘管我會推薦'package'運行測試。有關可能階段的詳細列表,請查看:http://maven.apache.org/ref/3.1.1/maven-core/lifecycles.html,以及http://maven.apache.org/guides/introduction/介紹到的,lifecycle.html。也許問題是,當你想運行exec目標時,這些類還沒有被編譯......? – carlspring
另外我注意到,maven-exec-plugin不支持'java'目標的多個擴展。更多信息在這裏:http://stackoverflow.com/questions/22562558/the-maven-exec-plugin-executes-only-first-execution – victor