【问题标题】:execute maven mainclass multiple times with different sets of arguments使用不同的参数集多次执行 maven mainclass
【发布时间】:2013-05-14 20:34:04
【问题描述】:

如何使用不同的参数多次调用 maven mainclass

<build>
<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
            <mainClass>TestExecutionInitiator</mainClass>
            <classpathScope>test</classpathScope>
            <arguments>
                <argument>Chrome</argument>
            </arguments>
        </configuration>
    </plugin>
</plugins>

到目前为止,我可以将我的主类传递参数设置为“Chrome”。 我想用另一个参数 Firefox 调用主类。 当我运行 mvn exec:java 我的主类应该调用多次。

【问题讨论】:

  • 您是否尝试过复制粘贴并制作更多插件元素副本?
  • 我尝试制作更多插件,但它只执行最后一个插件。

标签: maven maven-2


【解决方案1】:

您可以简单地使用如下几种执行方式:

<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <executions>
          <execution>
            <id>exec-1</id>
            <phase>test</phase>
            <goals><goal>exec</goal></goals>
            <configuration>
              <mainClass>TestExecutionInitiator</mainClass>
              <classpathScope>test</classpathScope>
              <arguments>
                  <argument>Chrome</argument>
              </arguments>
            </configuration>
          </execution>
          <execution>
            <id>exec-2</id>
            <phase>test</phase>
            <goals><goal>exec</goal></goals>
            <configuration>
              WhatEver Configuration
            </configuration>
          </execution>
        </executions>
    </plugin>
</plugins>

【讨论】:

  • 我尝试了上述配置,但它抛出错误“目标 org.codehaus.mojo:exec-maven-plugin:1.2.1:java 的参数'mainClass'丢失或无效”跨度>
  • 所以在两个执行中添加主类标签
【解决方案2】:

将参数作为 maven 环境变量传递:

<build>
<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
        <configuration>
            <mainClass>TestExecutionInitiator</mainClass>
            <classpathScope>test</classpathScope>
            <arguments>
                <argument>${myArg}</argument>
            </arguments>
        </configuration>
    </plugin>
</plugins>

并以这种方式执行:

mvn exec:exec -DmyArg=Chrome

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 2016-04-13
    • 2023-03-21
    相关资源
    最近更新 更多