是否有可能在一个POM中执行两个不同的maven exec-maven-plugin

我使用mvn exec:java com.mycompany.FooServer执行下面的代码mvn exec:java com.mycompany.FooServer

我想添加另一个服务器,我可以执行像mvn exec:java com.mycompany.BarServer

我如何在一个单独的文件中做到这一点?

 <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.mycompany.FooServer</mainClass> </configuration> </plugin> </build> 

尝试这个。 执行中可以有多个执行。 所有你需要做的是在执行下移动configuration元素。 该插件有configuration,但每个执行也可以有一个单独的configuration元素。

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

使用Maven 3.3.1及更高版本,您可以使用其ID来运行执行

 mvn exec:java@id 

在这种情况下,命令将是mvn exec:java@first-executionmvn exec:java@second-execution 。 看到这个答案的更多细节。

@tieTYT:您可以使用两个不同的configuration文件通过idselect执行:

mvntesting-Pmanager

mvntesting-Pproxy

 <profiles> <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>test</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>pt.inesc.proxy.Proxy</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>manager</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <phase>test</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>pt.inesc.manager.Manager</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> 

使用maven> 3.3.1,可以指定执行id为:

 mvn exec:java@execId 

对于包括configuration在执行块中的我没有工作,maven抱怨主类没有设置。 但是,由Dario的答案启发我回答这个问题如下:

 <profiles> <profile> <id>foo</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <mainClass>com.mycompany.FooServer</mainClass> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>bar</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <mainClass>com.mycompany.BarServer</mainClass> </configuration> </plugin> </plugins> </build> </profile> </profiles> 

然后允许您使用以下命令运行一台或另一台服务器:

 mvn exec:java -Pfoo 

要么

 mvn exec:java -Pbar 

干杯,

我怕你想要的是不可能的 。 我无法find一种方法来在.pom文件中使用不同的configuration直接调用相同的exec-maven-plugin目标( mvn exec:java )。

说, 你可以有多个exec-maven-plugin的执行 。 事情是你不能直接调用目标。 您必须使用多个执行并将它们绑定到特定的构build阶段。

你也可以使用下面的解决scheme,适合我 。 您仍然可以直接使用.pom中的configuration来调用一个目标:

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <executions> <execution> <id>Acceptance Tests</id> <phase>integration-test</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>pybot</executable> <arguments> <!--...--> </arguments> </configuration> </execution> </executions> <configuration> <mainClass>pt.jandias.someapp.persistence.SchemaGenerator</mainClass> <arguments> <!--...--> </arguments> </configuration> </plugin> 

一个可以使用mvn exec:javamvn integration-test的意愿。

我find了解决办法: I put <configuration> in <execution>

你可以使用mvn clean test -Pfoo,吧

 <profiles> <profile> <id>foo</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <executions> <execution> <id>CountContinusIntegr-execution</id> <phase>compile</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>com.mycompany.FooServer</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>bar</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> <executions> <execution> <id>CountContinusIntegr-execution</id> <phase>compile</phase> <goals> <goal>java</goal> </goals> <configuration> <mainClass>com.mycompany.BarServer</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>