问题描述
我需要在maven构建阶段执行几个Java类,但是插件仅在第一次执行时执行该类
I need to execute several java classes during maven build phase, but plugin executes only class from first execution
Pom:
<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>
<phase>test-compile</phase>
<configuration>
<mainClass>com.myPackage.AssignTest</mainClass>
</configuration>
</execution>
<execution>
<id>second</id>
<goals>
<goal>java</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<mainClass>com.myPackage.CompareTest</mainClass>
</configuration>
</execution>
</executions>
</plugin>
有人知道错误在哪里吗?
Does somebody know where is an error?
推荐答案
以防有人想要得到答案.通过实验,我发现java
目标不支持多个执行,但是exec
目标却支持.因此,只需将java转换为exec
In case someone will want an answer to this.From experimenting I've found that the java
goal does not support multiple executions, but the exec
goal does. So just transform java into exec
下面是一个如何使用exec
目标运行上述代码的示例.
Below is an example of how to run the above code with the exec
goal.
<executions>
<execution>
<id>execution-one</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath/>
<argument>com.myPackage.AssignTest</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>execution-two</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-cp</argument>
<classpath/>
<argument>com.myPackage.CompareTest</argument>
</arguments>
</configuration>
</execution>
</executions>
如果要运行的类驻留在实际代码中,则可能需要将exec目标绑定到compile
之后的阶段.否则,它们将直接从项目依赖项中提取.
If classes you want to run reside in your actual code, you will probably need to bind the exec goal to a phase after compile
. Else they will simply be picked up from the project dependencies.
这篇关于maven-exec-plugin仅执行第一次执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!