2

I'm working on a Maven project, and after resolving many configuration problems, finally I am able to build the project successfully in Eclipse. After selecting maven install and seeing build success, a .jar artifact is now created in the target folder.

OK. Now as for the execution, instead of manually running the .jar in command line (java -jar myJarFile.jar), how can I automatically run it inside Eclipse?

1

Use the exec-maven-plugin the run the java launcher with the jar argument during the integration-test phase:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-jar</argument>
            <argument>target/myJar-1.0-SNAPSHOT.jar</argument>
        </arguments>
    </configuration>
    <executions>
        <execution>
            <id>integration-test</id>
            <phase>integration-test</phase>
            <goals>
                <goal>integration-test</goal>
            </goals>
        </execution>
    </executions>
</plugin>

In Eclipse, right click, select Run As and choose Maven Test to run it.

References

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.