maven-exec-plugin只执行第一次执行

时间:2014-03-21 15:11:55

标签: java maven maven-plugin

我需要在maven构建阶段执行几个java类,但插件只执行第一次执行的类

波姆:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>first</id>
            <goals>
                <goal>java</goal>
            </goals>
            <phase>test-compile</phase>
            <configuration>
                <mainClass>com.myPackage.AssignTest</mainClass>
            </configuration>
        </execution>
        <execution>
            <id>second</id>
            <goals>
                <goal>java</goal>
            </goals>
            <phase>test-compile</phase>
            <configuration>
                <mainClass>com.myPackage.CompareTest</mainClass>
            </configuration>
        </execution>
    </executions>
</plugin>

有人知道哪里出错了吗?

1 个答案:

答案 0 :(得分:1)

如果有人想要回答这个问题。 通过实验,我发现java目标不支持多次执行,但exec目标确实如此。所以只需将java转换为exec

以下是如何使用exec目标运行上述代码的示例。

            <executions>
                <execution>
                    <id>execution-one</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>java</executable>
                        <arguments>
                            <argument>-cp</argument>
                            <classpath/>
                            <argument>com.myPackage.AssignTest</argument>
                        </arguments>
                    </configuration>
                </execution>
                <execution>
                    <id>execution-two</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>java</executable>
                        <arguments>
                             <argument>-cp</argument>
                             <classpath/>
                             <argument>com.myPackage.CompareTest</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>

如果要运行的类驻留在实际代码中,则可能需要将exec目标绑定到compile之后的阶段。否则,他们只会从项目依赖项中获取。

相关问题