Performance Zone is brought to you in partnership with:

Jason Whaley is a Java developer specializing in service oriented architectures, enterprise integration, cloud computing, and continuous integration. Previously, Jason has worked in multiple roles for both public companies as well as government institutions in a variety of roles for several broad ranging Java based projects. Presently, Jason works at Nodeable as a platform developer where he is helping build a next generation infrastructure monitoring and analytics tool. He is also a contributor to The Basement Coders Podcast. Jason is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

Debugging a Maven Build With mvnDebug

02.05.2013
| 3286 views |
  • submit to reddit

I ran into an interesting little debugging conundrum recently with IntelliJ’s debugger and maven.

I was loading a .war within the pre-integration-test phase of another module so I could run a set of intergration tests with the failsafe plugin that depend on that webapp being available. The purpose was to have that webapp loaded for some black box system testing at the end of the maven build. There was a test failure that was localized to this particular set of tests that I couldn’t quite sort out immediately. As usual, the next logical step is to attach a debugger.

Since these tests depended on the environment being setup and that environment setup was performed via maven, I couldn’t just Run->Debug on the test itself as I normally can with tests in IntelliJ. So in IntelliJ I first set my breakpoints, go to the maven pane, and hit debug on the install goal for system module. The set of tests run and none of my breakpoints were hit. Bummer.

It seems as though IntelliJ is not running maven with the debugging agent enabled even though I’ve explicity hit “Debug” on a maven goal.

I’m not entirely sure what was going on with IntelliJ in this instance but here’s how I got around it.

Ever since some earlier version of maven (2.0.8, I believe), maven has shipped with a little known executable in its bin/ directory named mvnDebug. In a nutshell, mvnDebug runs maven in all of its glory but includes the debugging arguments the jvm needs to listen for a debugger setup for you conveniently.

> alias mvnDebug=/usr/share/maven/bin/mvnDebug 
> mvnDebug clean install 
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000

This ends up being the equivalent of invoking java with the proper debugging arguments:

java ...  -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y

Then in IntelliJ (or your IDE/debugger of choice) set your breakpoints and connect your debugger to localhost:8000 and voila! My breakpoints ended up getting hit and that particular issue was resolved in a matter of minutes.



Published at DZone with permission of Jason Whaley, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)