Maven build debug in Eclipse

JavaEclipseDebuggingMaven

Java Problem Overview


I want to debug Eclipse build with tests. I tried to run it by Run > Debug Configurations > Maven Build. In Base directory is my Maven repo directory with pom.xml file, in goals 'clean install'. When I click on debug Eclipse starts build, run tests but it doesn't stops on breakpoints.

Java Solutions


Solution 1 - Java

Easiest way I find is to:

  1. Right click project

  2. Debug as -> Maven build ...

  3. In the goals field put -Dmaven.surefire.debug test

  4. In the parameters put a new parameter called forkCount with a value of 0 (previously was forkMode=never but it is deprecated and doesn't work anymore)

Set your breakpoints down and run this configuration and it should hit the breakpoint.

Solution 2 - Java

if you are using Maven 2.0.8+, then it will be very simple, run mvndebug from the console, and connect to it via Remote Debug Java Application with port 8000.

Solution 3 - Java

The Run/Debug configuration you're using is meant to let you run Maven on your workspace as if from the command line without leaving Eclipse.

Assuming your tests are JUnit based you should be able to debug them by choosing a source folder containing tests with the right button and choose Debug as... -> JUnit tests.

Solution 4 - Java

probleme : unit test result are not the same runing with eclipse and maven due ti order of library used by eclipse and maven. In my case the test was success with maven but i want to debug my unit test using eclipse, so the most easy way to debug unit test class with eclipse and runing maven is :

  1. mvn -Dtest=MySuperClassTest -Dmaven.surefire.debug test ==> it will listen to the 5005 port (default port)

  2. Go to eclipse, open a debug configuration, add a new java remote application and change the port to 5005 and debug

  3. of course you must add break point somewhere in the class that you want to debug

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaciej LaskowskiView Question on Stackoverflow
Solution 1 - Javaalex.pView Answer on Stackoverflow
Solution 2 - JavaRajeshView Answer on Stackoverflow
Solution 3 - JavaNicola MusattiView Answer on Stackoverflow
Solution 4 - JavaMohamed ChaabaniView Answer on Stackoverflow