Is it possible to execute two different maven-exec-maven-plugin in one POM

I am executing the following code using mvn exec:java com.mycompany.FooServer .

I would like to add another server that I can execute as mvn exec:java com.mycompany.BarServer .

How to do this in a single pom file?

 <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> 
+47
maven
Nov 24 2018-11-11T00:
source share
6 answers

Try it. You can perform several performances at run time. All you have to do is move the configuration item under execution. The plugin is configured, but each execution can also have a separate configuration item.

 <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> 

With Maven 3.3.1 and later, you can start execution by its identifier using

 mvn exec:java@id 

In this case, the commands will be mvn exec:java@first-execution and mvn exec:java@second-execution . See this answer for more details.

+62
Nov 24 '11 at 4:25
source share

@tieTYT: you can select execution by identifier using two different profiles:

mvn test -Pmanager

mvn test -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> 
+10
Mar 25 '14 at 15:27
source share

With maven> 3.3.1, you can specify the execution identifier as:

 mvn exec:java@execId 
+7
Oct 28 '15 at 9:43 on
source share

For me, including the configuration in the execution unit, it did not work, and maven complained that the main class was not installed. But, inspired by Dario, I will answer this question as follows:

 <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> 

Then you can start one or the other server using:

 mvn exec:java -Pfoo 

or

 mvn exec:java -Pbar 

Greetings

+2
Oct 23 '14 at 11:39 on
source share

I am afraid that what you want is impossible . I could not find a way to directly call the same path to exec-maven-plugin ( mvn exec:java ) with various configurations in the .pom file.

It is said that you can have several exec-maven-plugin executions . The fact is that you cannot directly name goals. You must use several executions and bind them to specific build steps.

You can also use the following solution that fits me . You can still directly name one target as your configuration in .pom:

 <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> 

You can use mvn exec:java and mvn integration-test as desired.

0
Sep 11 '14 at
source share

I find a solution: I put <configuration> in <execution>

you can use mvn clean test -Pfoo, bar

 <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> 
0
Dec 06 '16 at 16:01
source share



All Articles