简体   繁体   中英

Maven - Not able to Debug in Eclipse, when using surefire plugin

I have a pom.xml, which has following stuff declared

Plugins - maven-surefire-plugin, groovy-maven-plugin and maven-jar-plugin Along with this couple of dependencies for the project and a couple of profiles.

When i run the following command from command line things move as per expectation

mvn clean install -P testProfile

but when i try to run the same command from Eclipse(for debugging purpose), maven runs fine(maven tries to resolve the dependencies but further processing is halted due to errors) but debug mode is not launched ie it does stop at my breakpoints specified.

but when i try to debug the same project as JUnit it does stop at those breakpoints.

Any idea what I am doing wrong, when using maven.

If by running the same command from Eclipse what you mean is that you click the right mouse button and select Run as -> Maven install this is executed as an external program on your project's directory, not within Eclipse itself. That's why your breakpoints are not engaged.

Eclipse and maven do not play well together. Try hitting F5 to update and "cleaning" your project from under "project".

Well I have solved the problem.

It is due to usage of surefire-plugin.

When you use surefire plugin, it runs your tests in another forked process not in the current process, that's why you are not able to debug your code.

If you want to debug your code, you need to make sure that surefire does not fork the tests. For this put the following setting in your maven configuration before launching the debug

forkMode=never

This should do the job for you.

For more information visit surefire documentation page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM