我知道如何使用Eclipse调试远程Java虚拟机,但我如何对Java Web Start程序进行调试。我在Java Web Start中遇到了一个只出现的问题。这一定与安全有关。
我需要一个适用于当前Java VM(例如1.6.0_12)的解决方案。
我知道如何使用Eclipse调试远程Java虚拟机,但我如何对Java Web Start程序进行调试。我在Java Web Start中遇到了一个只出现的问题。这一定与安全有关。
我需要一个适用于当前Java VM(例如1.6.0_12)的解决方案。
与远程调试其他Java进程的方法类似:您需要为VM设置一些参数(-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=12345
),然后连接指定的端口。在Java Web Start 6.0中,可以通过使用-J选项来完成此操作,在早期版本中则是通过环境变量JAVAWS_VM_ARGS来完成。详情请参见这里。
手动启动 JWS VM。这样你可以提供启动参数来打开调试端口。以下是一个描述,步骤如下:
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
JAVAWS_VM_ARGS
时,必须省略双引号。例如,set JAVAWS_VM_ARGS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8989,server=y,suspend=n
。 - Jaime Hablutzel对于新版本的Java(Java 8u20+和Java 7u70+),我发现像-Xrunjdwp这样的参数不能直接传递,也不能使用JAVAWS_VM_ARGS传递。
消息
Rejecting attempt to specify insecure property: -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
开始在控制台输出中显示。
唯一有效的解决方案是将这些参数传递到JAVA_TOOL_OPTIONS系统变量中。
javaws.exe -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 http://server:port/descriptor.jnlp
Enable the Java logs and tracing in the Java Control Panel > Advanced.
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:
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
使用javax.net.debug=all参数,您可以查看握手过程,如果jnlp内部的jar文件是从https连接加载的,则会显示。这种问题很难调试。
...
%% 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:
使用Java 8和Windows 10,在命令提示符(cmd.exe)中输入以下内容:
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
在此之后,使用Eclipse(或其他IDE)启动远程Java应用程序调试设置到上述命令中使用的端口(在本例中为8000
)。
您可以启用调试模式运行JNLP:
javaws -Xnosplash -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009 <application>.jnlp
输出: 正在监听传输 dt_socket 的地址: 5009
使用您喜欢的IDE附加到此,我使用的是IntelliJ IDEA。 运行>附加到进程
~/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 "$@"
set JAVAWS_TRACE_NATIVE=1
set JAVA_TOOL_OPTIONS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8989,server=y,suspend=y
javaws -Xnofork my_jnlp_file.jnlp
-Xnofork
是必需的,否则设置不会应用于应用程序的分叉JVM。
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
。 - Joaquim Oliveirajavaws
会在指定端口上打开调试器,然后启动另一个JVM,它也会尝试做同样的事情。最终结果是“地址已经在使用中”,JVM退出。 - Jason