Monday, October 21, 2013

Remote debugging a java application

You can remote debug a running applet. Set it in the Java control panel, in "runtime parameters" for the JRE
-Djava.compiler=NONE -Xnoagent -Xdebug 
-Xrunjdwp:transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n for JVM 1.4
or -agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n for JVM 1.5 and newer

These are considered insecure JVM parameters and will cause the LiveConnect error: "This application is going to perform an insecure operation" See StackOverflow LINK for more info


How to set the parameters:


This is equivalent to setting the JAVA_OPTS environment variable.


The settings in Eclipse:


For the uninitiated: the idea is that the JVM starting the applet looks at the server parameter. If it's set to 'y' then the applet running JVM acts as a debugging server. You then from Eclipse (or another IDE) connect with Socket Attach. You start the application, and start the debugging session in your IDE, which connects to the running applet.

 If you set server=n then in Eclipse you set the connection type to Socket Listen,  which means that Eclipse acts as a debugging server. You start the debugging session in Eclipse, the debugging server starts and waits. You then start the web application (or applet) which will connect to Eclipse).

If you need to debug the whole applet loading procedure You can set the suspend=y parameter. You start the web application, and the applet start will be paused, waiting for you to start the debugging session against it.

Note: Enabling JWDP debugging seems to break running through a proxy ( such as fiddler ). The control pannel settings for network and proxy are ignored, and proxy=DIRECT is chosen always