Debugging Java WebStart applications with Eclipse

The last couple of days I went through a little nightmare: I needed to debug a Java application which showed some weird behaviour only when loaded via WebStart, but not when executed within Eclipse.

[Multiple](http://www.jacoozi.com/index.php?option=com_content&task=view&id=119&Itemid=134) [internet](http://javaswamy.blogspot.com/2008/10/debugging-jws-with-eclipse.html) [resources](http://www.ibm.com/developerworks/java/library/os-eclipse-javadebug/index.html) told me to use the `JAVAWS_VM_ARGS` environment variable to tell the Java VM to either create a debug socket itself or connect to some socket started from Eclipse and then simply set a breakpoint there and wait for the meal. But nothing worked out for me, until I found two very important issues nobody wrote about so far:

* Under Java 6 `JAVAWS_VM_ARGS` seems to be completely ignored by `javaws`, on Linux and on Windows. The way to go was to use separate `-J` options in the call to `javaws` – and given a running Eclipse debug server you finally saw the threads of your running application.
* Wait, were these threads really belonging to _your_ running application? This was the second issue. Apparently `javaws` directly forks away as soon as it started and runs your application in a separate VM, which _of course_ did not get the original debug options passed. Again, some internet resources said it would be enough to load the jnlp file from the net and start locally, but actually this did not work out. The magic option to apply to `javaws` here was `-Xnofork` and finally, on the next run I saw my application’s threads in Eclipse and my breakpoints magically worked as expected.

Here is the complete command line example again (given a running Eclipse debug server on port 8000):

javaws -Xnofork -J-Xdebug -J-Xnoagent \
-J-Xrunjdwp:transport=dt_socket,server=n,address=8000 \
path/to/app.jnlp

Hope that helps someone 🙂

10 thoughts on “Debugging Java WebStart applications with Eclipse”

  1. Hi, i’ve a problem.
    Javaws is running now in debug mode (Listening for transport dt_socket at address: 8000
    ) but i get connection refused error (Failed to connect to remote VM. Connection refused) in eclipse

    What am I doing wrong?

    Connection Type: socket attach
    host: localhost
    port: 8000

  2. Ok, your call seems to be correct. Check whether the remote debug server is really running with netstat -an | grep 8000. If this is there, try to connect to it via telnet. If this also works out there is actually no reason for eclipse not being able to connect to it.

  3. I tried both types: eclispe as debug server or javaws as debug server. In both ways the connection is established only for a very short time and is immediately terminated.

    I guess the -XnoFork parameter isn’t working for me.

    What Java Version do you use?

    javaws -verbose -wait -Xnofork -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,address=8000,server=n,suspend=n http://localhost:8080/myApplication/start.jnlp
    Java(TM) Web Start 1.6.0_21 Launching: /opt/jdk1.6.0_21/jre/bin/java
    /opt/jdk1.6.0_21/jre/bin/java
    -Xbootclasspath/a:/opt/jdk1.6.0_21/jre/lib/javaws.jar:/opt/jdk1.6.0_21/jre/lib/deploy.jar:/opt/jdk1.6.0_21/jre/lib/plugin.jar
    -classpath
    /opt/jdk1.6.0_21/jre/lib/deploy.jar
    -Djava.security.policy=file:/opt/jdk1.6.0_21/jre/lib/security/javaws.policy
    -DtrustProxy=true
    -Xverify:remote
    -Djnlpx.home=/opt/jdk1.6.0_21/jre/bin
    -Dsun.awt.warmup=true
    -Djnlpx.origFilenameArg=http://localhost:8080/myApplication/start.jnlp
    -Djnlpx.remove=false
    -Djnlpx.splashport=38695
    -Xdebug
    -Xnoagent
    -Xrunjdwp:transport=dt_socket,address=8000,server=n,suspend=n
    -Djnlpx.jvm=/opt/jdk1.6.0_21/jre/bin/java
    -Djnlpx.vmargs=”-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8000,server=n,suspend=n”
    com.sun.javaws.Main
    -wait
    -Xnofork

  4. 1.6.0_18 here on my side, but this shouldn’t matter much. You probably have a different issue here, maybe try setting suspend=y, so the debugger stops as early as it can and you get a grasp what is actually causing the closing of the debug connection. Sorry for not being of more help.

  5. I had the similar problem, and just got it resolved.

    The situation you described happens when you generate your jnlp text on the fly. To resolve this, I paste the generated text to a local jnlp text file, and let javaws to start this local jnlp file.

    Hope this helps.

  6. I am trying to start a WebStart application that is usually started from an already-running JBoss application. The JNLP file is generated on-the-fly and downloaded to the client-machine where it uses a Cookie and the Session ID of the already-running session to re-connect to the already-running JBoss deployment. Becasue the file is generated on-the-fly I cannot use it to start WebStart from the command-line in the manner you describe. I did try it but it doesn’t work even if the JBoss deployment is still running. Is there any other way I can specify that WebStart should start in DEBUG mode? My preference would be to be specify something in an environment variable as before. Thank you.

Comments are closed.