我有一个Maven项目,它在src文件夹的一个包中有2个主电源(MyTestApp_A和MyTestApp_B).
如果我打开它们并单击运行按钮,我可以在Eclipse中运行这些"main"类.但是,Eclipse有问题,因此我实际上需要使用Maven在命令行上运行这两个类.
我之前从未使用过Maven,但在寻求帮助并进行一些研究后,我明白我必须更改pom.xml文件.
因此,我已成功更改了我的pom.xml文件,以使用以下命令运行其中一个应用程序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>
Run Code Online (Sandbox Code Playgroud)
很高兴能够运行MyTestApp_A,我尝试添加另一个配置部件来运行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>
Run Code Online (Sandbox Code Playgroud)
但是,此文件格式不正确.显然我不允许<configuration>在同一个pom.xml文件中有2个标签.
那么,我如何使用Maven执行MyTestApp_A和MyTestApp_B?如何配置pom.xml文件?
尝试对要执行的每个主类使用执行:
<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>
Run Code Online (Sandbox Code Playgroud)