RSS Feed

New Adventures in Software


Debugging Java Web Start Applications

Posted in Java by Dan on February 6th, 2009

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.jnlp

You can then attach the debugger as normal.

3 Responses to 'Debugging Java Web Start Applications'

Subscribe to comments with RSS


  1. on February 8th, 2009 at 10:38 am

    Those parameters:

    -Xnoagent
    -Djava.compiler=NONE

    are not required with hotspot.

    Gruss
    Bernd

  2. Adi said,

    on February 9th, 2009 at 8:43 am

    ‘export JAVA_VM_ARGS=”-Xdebug -Xnoagent blah blah”
    javaws http://www.example.com/path_to/application.jnlp
    It should be

    ‘export JAVAWS_VM_ARGS=”-Xdebug -Xnoagent blah blah”
    javaws http://www.example.com/path_to/application.jnlp

    Is it typo? :)

    With this option, if you have one JNLP application that launches other JNLP application, the second JNLP application won’t work. I faced this problem long time ago. I can not give you exact ‘JAVAWS_VM_ARGS’ that I had to reproduce this scenario.

  3. Dan said,

    on February 9th, 2009 at 4:29 pm

    @Adi, yes it is a typo, thanks for pointing it out.

    @Bernd, you are right, those are just the default general-purpose options that IDEA suggests.