DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Introduction to Tactical DDD With Java: Steps to Build Semantic Code
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • How to Build and Optimize AI Models for Real-World Applications

Trending

  • Every Cache Miss Is a Tiny Tax on Your Performance
  • How to Interpret the Number of Spring ApplicationContexts in Integration Tests
  • The Middleware Gap in AI Agent Frameworks
  • Spring Boot Done Right: Lessons From a 400-Module Codebase
  1. DZone
  2. Coding
  3. Java
  4. Debugging a Maven Build With mvnDebug

Debugging a Maven Build With mvnDebug

By 
Jason Whaley user avatar
Jason Whaley
·
Feb. 05, 13 · Interview
Likes (3)
Comment
Save
Tweet
Share
71.8K Views

Join the DZone community and get the full member experience.

Join For Free

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.



Apache Maven Build (game engine)

Published at DZone with permission of Jason Whaley. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Introduction to Tactical DDD With Java: Steps to Build Semantic Code
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • How to Build and Optimize AI Models for Real-World Applications

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook