是否可以在单个POM中执行两个不同的Maven exec-maven-plugin [英] Is it possible to execute two different maven exec-maven-plugin in a single POM

查看:90
本文介绍了是否可以在单个POM中执行两个不同的Maven exec-maven-plugin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

如何在单个pom文件中做到这一点?

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>  

推荐答案

尝试一下.您可以在处决中执行多个处决.您需要做的就是将配置元素移到执行下.该插件具有配置,但是每次执行也可以具有单独的配置元素.

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>

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

With Maven 3.3.1 and up, you can run an execution by its ID using

mvn exec:java@id

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

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

这篇关于是否可以在单个POM中执行两个不同的Maven exec-maven-plugin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆