Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

maven

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

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

How do I do that within 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>   
like image 854
diya Avatar asked Nov 24 '11 04:11

diya


People also ask

What is the use of exec maven plugin?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec – can be used to execute any program in a separate process. exec:java – can be used to run a Java program in the same VM.

What is executions in maven?

An <execution> causes the plugin to be executed during the maven build lifecycle, i.e. during your build. The <configuration> allows you to configure the plugin for how it should behave during execution. Many Maven plugins provide documentation about their configuration options, e.g. the maven-compiler-plugin.


2 Answers

Try this. You can have more than one execution under executions. All you need to do is move the configuration element under the execution. The plugin has configuration, but each execution can also have a separate configuration element.

<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 up, you can run an execution by its ID using

mvn exec:java@id 

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

like image 93
Tim O'Brien Avatar answered Sep 20 '22 11:09

Tim O'Brien


@tieTYT: You can select the execution by id using two distinct 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> 
like image 35
dario nascimento Avatar answered Sep 19 '22 11:09

dario nascimento