Reputation: 17574
I have a Maven project and it has 2 mains (MyTestApp_A, and MyTestApp_B) inside one of the packages from the src folder.
I can run these "main" classes in Eclipse if I open them and click the run button. However, Eclipse is bugged, and so I actually need to run these two classes on a command line using Maven.
I have never used Maven before, but after asking for help and doing some research I understand that I have to change the pom.xml file.
Consequently, I have altered my pom.xml file successfully to run one of the apps using the command mvn exec:java -Dexec.mainClass="servers.MyTestApp_B"
:
<plugins>
<!-- Allows the example to be run via 'mvn compile exec:java' -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>servers.MyTestApp_A</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</plugin>
</plugins>
Happy with being able to run MyTestApp_A, I tried to add another configuration part to run MyTestApp_B:
<plugins>
<!-- Allows the example to be run via 'mvn compile exec:java' -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>servers.MyTestApp_A</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
<configuration>
<mainClass>servers.MyTestApp_B</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</plugin>
</plugins>
However, This file is not well formed. Apparently I am not allowed to have 2 <configuration>
tags in the same pom.xml file.
So, how can I execute MyTestApp_A, and MyTestApp_B using Maven? How do I configure the pom.xml file?
Upvotes: 3
Views: 7177
Reputation: 22830
Try using executions for each main class you want to execute:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>MyTestApp_A</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>servers.MyTestApp_A</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</execution>
<execution>
<id>MyTestApp_B</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>servers.MyTestApp_B</mainClass>
<includePluginDependencies>false</includePluginDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Upvotes: 6