Debugging Java Web Start Applications
How do you attach a debugger to a Java Web Start application? Normally you probably wouldn’t bother, just start the application without Web Start and debug as normal. However, if you have a bug that shows up only when running in the Web Start sandbox, as I did today, that won’t help.
The SecurityManager restrictions were causing a different branch of my code to be executed than when launching the application from IDEA or the command line. It was not immediately obvious how to attach the debugger to the Web-Started VM.
In IDEA, to remotely attach a debugger to the JVM, you should start the VM with following set of switches (or similar):
-Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
Where do these switches go when launching a Web Start application? Normally you launch the application by just clicking a JNLP link in your browser. One option, which doesn’t work, is to specify the JVM arguments in JNLP file. You can already do something like this:
<j2se version="1.5+" java-vm-args="-ea -server"/>
Adding the debug switches is trivial… and futile. The problem is that remote debugging requires the VM to open up a socket to accept connections from the debugger. Rather sensibly, Web Start does not permit untrusted applications to open sockets on users’ machines. I don’t know if it would work if the application was signed, I was too lazy to go through the hassle of signing the code.
If you want to open a socket on the client machine for debugging purposes, you are going to have to do it from the client machine rather than the JNLP file. The solution is to set the JAVAWS_VM_ARGS environment variable to include the debug switches and then to launch the javaws executable and point it at the unmodified JNLP file. From a bash shell it looks like this:
export JAVAWS_VM_ARGS="-Xdebug -Xnoagent blah blah" javaws http://www.example.com/path_to/application.jnlpYou can then attach the debugger as normal.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)






Comments
Matthew McCullough replied on Mon, 2009/02/09 - 10:47am
Mike Miller replied on Tue, 2009/02/10 - 10:46am
Another option similiar to the one shown (pointing to the JNLP URL) is to point to a copy of the downloaded JNLP file that you saved to your file system and pass that filepath to as a command line parm.
We have several JNLP clients and support both 1.4 and 1.5. I noticed some strangeness at times when attempting to debug a process using 1.4 and having the JAVAWS_VM_ARGS defined. I got to the point where I only defined that environment variable when I specifically was attempting to debug one of the JNLP clients.