Bulletproof debugging method to debug Java remote debugging

JVM remote debugging can be sometime tricky and elusive — especially when the process is running as a service. How can you separate JVM issues from other factors such as process running as service as a different user, firewall blocking debug port. One way to separate these is to know a bulletproof configuration for JVM remote debugging. Without further ado, here it is:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

Note that this only applies to Java 5 and above. If you are still in stone ages, hopefully you are not reading this blog either. This is great but how can I test it quickly? I still can’t connect. My server runs headless Linux environment, and I don’t have access to my pretty IDE. One method to use telnet.

telnet silly.example.com 5005

It works but there is something better. Command line jdb and its little known use to connect to remote process. You can also use it do debugging if you like.

/usr/java/current/bin/jdb -connect com.sun.jdi.SocketAttach:hostname=silly.example.com,port=5005
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb …
> exit

Maven debug output

Imagine you are frustrated by one of the maven plugin and you want to turn the debug output on. Google debugging a maven plugin or maven debug output and you may still be out of luck. Here is the brute force way of doing it.
Open MAVEN_HOME/core/plexus-container-default-1.0-alpha-9.jar and edit org/codehaus/plexus/plexus-bootstrap.xml to set threshold to debug.

<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>
org.codehaus.plexus.logging.console.ConsoleLoggerManager
</implementation>
<lifecycle-handler>basic</LIFECYCLE-HANDLER>
<configuration>
<threshold>debug</threshold>
</configuration>
</component>

Create a free website or blog at WordPress.com.