1

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?

0

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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