MVN在执行前编译 [英] Mvn compile before exec
问题描述
我正在尝试设置我的POM,这样当我执行mvn exec:exec
或mvn exec:java
时,它将首先编译源文件并且仅在成功时执行它.
I am trying to set up my POM such that when I do mvn exec:exec
or mvn exec:java
it will first compile the source and iff successful, execute it.
我有以下内容,并尝试过移动<execution>
部分,但无法使其正常工作:
I have the following and have tried moving the <execution>
part about but can't get it to work:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<phase>exec</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>my.main.class</mainClass>
</configuration>
</plugin>
</plugins>
</build>
当我执行mvn exec:exec ...
或mvn exec:java
时,它不会首先编译.我尝试将<execution>
部分放在exec
插件部分中,但是那也不起作用?
When I do either mvn exec:exec ...
or mvn exec:java
it doesn't first compile. I have tried putting the <execution>
part in the exec
plugin section but that didn't work either?
推荐答案
这是一个古老的话题,但是其他人可能对此感兴趣的替代解决方案感兴趣.
It's an old topic, but someone else might be interested in an alternative solution for this.
这并不是您想要的,但是您可以使用一个命令进行编译和执行:
It's not exactly what you were looking for, but you can compile and execute using a single command:
mvn compile exec:exec
这样, Maven 将始终在执行项目之前对其进行编译.
This way Maven will always compile the project before executing it.
这篇关于MVN在执行前编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!