【问题标题】:Fails using twice the MOJO's exec-maven-plugin使用两次 MOJO 的 exec-maven-plugin 失败
【发布时间】:2015-01-23 07:38:35
【问题描述】:

我尝试运行两次 MOJO 的 exec-maven-plugin,但它抱怨 mainClass 未设置。有了这个 my.Main 我想生成几个文件,它们必须在编译阶段之前完成。我做错了什么?使用正确的参数为两个执行设置了 mainClass。

我的 pom.xml 包含这个:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
        <execution>
            <id>ABC_FALSE</id>
            <phase>generate-sources</phase>
            <configuration>
                <mainClass>my.Main</mainClass>
                <arguments>
                    <argument>-abc</argument>
                    <argument>false</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
        <execution>
            <id>ABC_TRUE</id>
            <phase>generate-sources</phase>
            <configuration>
                <mainClass>my.Main</mainClass>
                <arguments>
                    <argument>-abc</argument>
                    <argument>true</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

运行后

mvn exec:java

我收到此错误

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java (default-cli) on project exec-generation: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.3.2:java are missing or invalid.

最好的问候, SK

【问题讨论】:

    标签: maven


    【解决方案1】:

    试试这个:

    ...
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
            <execution>
                <id>exucute_the_executable_jar_1</id>
                <phase>generate-resources</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>the.Main</mainClass>
                    <arguments>
                        <argument>a</argument>
                    </arguments>
                </configuration>
            </execution>
            <execution>
                <id>exucute_the_executable_jar_2</id>
                <phase>generate-resources</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>the.Main</mainClass>
                    <arguments>
                        <argument>b</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
    ...
    

    通过使用以下命令调用 maven:

    mvn package
    

    好的,我在 generate-resources 阶段使用它,但你可以更改它。

    最好的问候, 格拉夫

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-29
      • 2018-07-09
      • 1970-01-01
      • 2010-11-26
      • 2020-10-04
      • 2021-03-31
      • 1970-01-01
      相关资源
      最近更新 更多