The maven-exec-plugin executes only first execution

时间秒杀一切 提交于 2019-12-11 11:02:47

问题


I need to execute several java classes during maven build phase, but plugin executes only class from first execution

Pom:

<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>

Does somebody know where is an error?


回答1:


In case someone will want an answer to this. From experimenting I've found that the java goal does not support multiple executions, but the exec goal does. So just transform java into exec

Below is an example of how to run the above code with the exec goal.

            <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>

If classes you want to run reside in your actual code, you will probably need to bind the exec goal to a phase after compile. Else they will simply be picked up from the project dependencies.



来源:https://stackoverflow.com/questions/22562558/the-maven-exec-plugin-executes-only-first-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!