Toggle Java Debugger for Maven

Sometimes when creating a Maven plugin (Mojo) or when running java tools with maven using the exec plugin it’s helpful to debug the actual JVM that’s been started by maven. This is a snippet which you can throw into your ~/.bashrc to allow you to quickly toggle in and out of debug mode for Maven. Tweak the java debugger settings as you wish, as configured this will cause maven to wait on port 5005 for a remote debugger to attach.

Snippet

Example Usage

$ mavenDebugOn
$ mvn exec:java -Dexec.mainClass="com.jontodd.MyClass"
Listening for transport dt_socket at address: 5005
...
$ mavenDebugOff
Short URL: http://goo.gl/6c2aq

Leave a Reply

Your email address will not be published. Required fields are marked *