user3446915
user3446915

Reputation: 11

The maven-exec-plugin executes only first execution

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?

Upvotes: 1

Views: 1136

Answers (1)

victor
victor

Reputation: 1676

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.

Upvotes: 1

Related Questions