Debugging any Java Application

Post Java 5 update :(the old one still works but is spread in 2 JVM options, versus one)

As long as you’re using a java application (ie an application calling your JVM), you can enable the debug mode with these parameters :

-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y

So for example, if you want to debug an ant launch (launched via « ant -f myBuild.xml » for example), you simply have to set ANT_OPTS; on windows :

set ANT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y

Another example, with JBoss :

set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y

and then you can debug your launch with Eclipse, for example, creating a new debug configuration (remote java application on port 8787) !
Option : you can choose whether or not the application should wait for your debugger setting suspend to y or n.