Debugging Maven projects with Eclipse
Posted by Martin Homik | Posted in Java, WebApp | Posted on 31-07-2008
1
Debugging Maven projects with Eclipse or any other IDE on Windows is not trivial. In the beginning. But once you know the mechansim, it’s simple. I googled and found a few helpful pages. Look here. Here are my experiences.
Maven supports two debug modes: the Generic and the Surefire. If you want to debug maven itself, one of maven’s plugins, or a maven project, use the Generic Approach. If you want to debug a test in your project launched by surefire, use the Surefire Approach.
Surefire Approach.
- Create a new Java Project and call it “Maven Debug”. This Project will never have any source code in it, it is just a shell for attaching the debugger.
- Create a debug configuration: Run -> Debug Configurations and then right click on Remote Java Application and select New launch configuration. Call it “Maven Surefire”.
- Â On the Connect tab click the Browse button and select the “Maven Debug” project.
- Set connection properties to localhost and port 5005. This is the port on which Surefire waits for the debugger.
- The connection type is Standard (Socket Attach)
- On the Source tab add all projects that have any Maven source that you want to debug.
Now let’s do the actual debugging.
- Select break points in the code you’re are going to run. Note, you cn select only code in your test classes. It won’t work on classes outside the test phase.
- In your command line, append the following switch to your maven command: -Dmaven.surefire.debug. For example, to debug the tests run by the maven lifecycle install do mvn install -Dmaven.surefire.debug
- Wait for maven to pause its execution and display the message: Listening for transport dt_socket at address: 5005
- Attach the debugger to the running maven by selecting the “Maven Surefire” debug configuration created above. Your debugger should stop at your breakpoint.
Generic Approach.
- Follow the instructions, presented here. The only instructions that worked for me. They are very similar to the Surefire Approach.
- Note: use Maven 2.0.8 or higher. The, you don’t need to write your own maven debug script. It’ll be sufficient to use the shipped mvnDebug script.


Great instruction! I have something to add though. About Generic Debugging: there is a better/simpler way – see this link for a visual and intuitive instruction: http://it-worx.blogspot.com/2010/03/debug-maven-project-in-eclipse.html