How can I debug applications under Java Web Start (JNLP)?

JavaDebuggingJnlpJava Web-Start

Java Problem Overview


I know how I can debug a remote Java VM with Eclipse, but how can I do it with a Java Web Start program. I have a problem that only occurs in Java Web Start. It must be security related.

I need a solution that will work with a current Java VM like 1.6.0_12.

Java Solutions


Solution 1 - Java

It's quite the same like with any other Java process you want to debug remotely: You have to set up some arguments for the VM (-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=12345 ) and then connect to the given port. In Java webstart 6.0 this can be done with the -J option, in earlier version via environment variable JAVAWS_VM_ARGS. See details here.

Solution 2 - Java

Start the JWS VM manually. This way you can provide the startup parameters to open the debug port. Here is a description, it goes like this:

set JAVAWS_TRACE_NATIVE=1
set JAVAWS_VM_ARGS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8989,server=y,suspend=n"
javaws http://server:port/descriptor.jnlp

Solution 3 - Java

As for newer versions of Java (Java 8u20+ and Java 7u70+) i experienced that parameters like -Xrunjdwp cannot be passed directly nor using JAVAWS_VM_ARGS. Message Rejecting attempt to specify insecure property: -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 started to show up in console output.

The only solution that worked for me was to pass those arguments into JAVA_TOOL_OPTIONS system variable.

Solution 4 - Java

You can also provide the debug parameter to the javaws executable using the -J option

Example:

javaws.exe -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 http://server:port/descriptor.jnlp

Solution 5 - Java

You will need to do the following:

  1. Enable the Java logs and tracing in the Java Control Panel > Advanced. Java Control Panel: logs and tracing

  2. Enable parameters for debugging Java (optional but useful i.e. problems with tls/ssl handshake as close_notify or handshake_failure) & launching the JNLP, there are two ways you can do it:

2.a. Download the JNLP file and execute it from command line (the SET command is not required in this particular case).

    set JAVA_TOOL_OPTIONS=-Djavax.net.debug=all
    javaws -wait jnlp.jnlp

2.b. Add arguments (i.e. -Djavax.net.debug=all) for the JVM in the Java Control Panel > Java > View (this is not required in this particular), and launch the JNLP file from browser:

[![Java Control Panel: jvm arguments][2]][2]

3. The logs and traces are located in the log directory from the Java Deployment Home from where I paste these locations:

a. Windows XP: %HOME%\Application Data\Sun\Java\Deployment

b. Windows 7/Vista: %APPDATA%\..\LocalLow\Sun\Java\Deployment

c. Linux/Solaris: %HOME%/.java/deployment

With javax.net.debug=all you will see the handshake if the jar inside the jnlp is loaded from an https connection. This kind of problems are hard to debug.

...
%% No cached client session
*** ClientHello, TLSv1.2
...
***
... 
Java Web Start Main Thread, received EOFException: error
Java Web Start Main Thread, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
Java Web Start Main Thread, SEND TLSv1.2 ALERT:  fatal, description = handshake_failure
Java Web Start Main Thread, WRITE: TLSv1.2 Alert, length = 2
Java Web Start Main Thread, called closeSocket()
#### Java Web Start Error:

Solution 6 - Java

To debug a Web Start application in Linux, create a shell script ~/bin/javaws-debug.sh with the javaws invocation in debug mode as described above:

~/bin/javaws-debug.sh:

#!/bin/sh
export JAVAWS_TRACE_NATIVE=1
export JAVAWS_VM_ARGS="-Xdebug -Xnoagent -Djava.compiler=NONE 
  -Xrunjdwp:transport=dt_socket,address=8989,server=y,suspend=n"
javaws "$@"

Then, in your browser, choose that script as the application to invoke on jnlp files.

For example, in Firefox, go to Edit→Preferences→Applications, Content Type: Java Web Start, and choose "Use Other" in Action and pick the script from the "Select Helper Application" dialog. In Chrome, you need to alter Linux system settings. In KDE, go to System Settings→File Associations, Known Types: application:x-java-jnlp-file, add a new Application, pick ~/bin/javaws-debug.sh from the "Choose Application for application/x-java-jnlp-file" dialog.

Once your browser is configured, Java Web Start application will start using your wrapper, which will enable debugger to connect on port 8989.

Solution 7 - Java

With Java 8 and Windows 10, open command prompt (cmd.exe) and type this:

set JAVAWS_TRACE_NATIVE=1
set JAVA_TOOL_OPTIONS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
javaws java-app.jnlp

Solution 8 - Java

You can run your JNLP with debugging enabled:

javaws -Xnosplash -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009 <application>.jnlp

Output: Listening for transport dt_socket at address: 5009

Attach to this with your favorite IDE, I use IntelliJ IDEA Run>Attach to process

Solution 9 - Java

Have you tried printing a debug log? That is a useful thing to have at any rate, and might help in this case.

If you want real debugging, see e.g. here: How can I debug under WebStart?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHorcrux7View Question on Stackoverflow
Solution 1 - JavaKai HuppmannView Answer on Stackoverflow
Solution 2 - JavamkoellerView Answer on Stackoverflow
Solution 3 - JavaVojtěch TůmaView Answer on Stackoverflow
Solution 4 - JavaMarco MontelView Answer on Stackoverflow
Solution 5 - JavalmiguelmhView Answer on Stackoverflow
Solution 6 - JavaNicholas SushkinView Answer on Stackoverflow
Solution 7 - JavaqwertzguyView Answer on Stackoverflow
Solution 8 - JavaJorduinoView Answer on Stackoverflow
Solution 9 - JavasleskeView Answer on Stackoverflow