是否可以在单个POM中执行两个不同的maven exec-maven-plugin

diy*_*iya 56 maven

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

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

我如何在一个pom文件中执行此操作?

<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>  
Run Code Online (Sandbox Code Playgroud)

Tim*_*ien 86

试试这个.您可以在执行下执行多个执行.您需要做的就是在执行时移动配置元素.该插件具有配置,但每次执行也可以具有单独的配置元素.

<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>
Run Code Online (Sandbox Code Playgroud)

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

mvn exec:java@id
Run Code Online (Sandbox Code Playgroud)

在这种情况下,命令将是mvn exec:java@first-executionmvn exec:java@second-execution.有关详细信息,请参阅此答案.

  • 对于那些想知道你如何通过id调用执行的人,[我的搜索](http://stackoverflow.com/questions/2192660/maven-maven-exec-plugin-multiple-execution-configurations)没有出现这样做的方法. (7认同)
  • @DanielKaplan是的,使用maven> 3.3.1你用`mvn exec来调用id执行:java @ execId` (5认同)

dar*_*nto 10

@tieTYT:您可以使用两个不同的配置文件选择id执行:

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>
Run Code Online (Sandbox Code Playgroud)


Geo*_*rge 9

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

mvn exec:java@execId
Run Code Online (Sandbox Code Playgroud)