2013-08-21 88 views
10

我想设置我的POM,当我做mvn exec:execmvn exec:java时它会首先编译源代码并且iff成功执行它。Mvn在执行前编译

我有以下并试图移动<execution>部分有关,但不能得到它的工作:

<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插件部分,但那也不起作用?

+0

为什么不在exec:exec/exec:java之前运行“compiler:compile”? –

+2

@Elad我一直忘记编译,然后弄糊涂为什么没有改变。 – Lerp

+0

@Lerp面对同样的问题,你有没有找到解决方案? – Yaroslav

回答

1

可以Exec插件结合(在下面的例子中verify)以下在build lifecyclecompile一个相:

<profile> 
    <id>proxy</id> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.2.1</version> 
       <executions> 
        <execution> 
         <phase>verify</phase> 
         <goals> 
          <goal>exec</goal> 
         </goals> 
         <configuration> 
          <mainClass>my.main.class</mainClass> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</profile> 

和比运行mvn verify

我看到答案很晚,你可能已经找到了解决方案。 我只是将其作为可能需要它的人的参考。

+3

谢谢你,但是,如果我正确理解,OP正试图在[mvn exec:[exec | java]'和** not ** [直接]执行期间进行编译,作为'普通'Maven构建周期的一部分。为了澄清,他们和我一样,希望在我们运行'mvn exec'时首先构建代码,但是在正常的Maven构建周期/阶段期间,不要**需要'exec'运行。 –

0

这是一个老话题,但其他人可能会对此有其他解决方案感兴趣。

这不正是你要找的,但你可以编译和使用一个命令执行:

mvn compile exec:exec 

这样的Maven执行前将一直编译项目。