如何在 Java Web Start (JNLP) 下调试应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/686061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I debug applications under Java Web Start (JNLP)?
提问by Horcrux7
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.
我知道如何使用 Eclipse 调试远程 Java VM,但如何使用 Java Web Start 程序进行调试。我有一个只出现在 Java Web Start 中的问题。它必须与安全相关。
I need a solution that will work with a current Java VM like 1.6.0_12.
我需要一个适用于当前 Java VM(如 1.6.0_12)的解决方案。
采纳答案by Kai Huppmann
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.
这与您想要远程调试的任何其他 Java 进程完全相同:您必须为 VM ( -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=12345
)设置一些参数,然后连接到给定的端口。在 Java webstart 6.0 中,这可以使用 -J 选项完成,在早期版本中通过环境变量 JAVAWS_VM_ARGS 完成。在此处查看详细信息。
回答by sleske
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?
如果您想要真正的调试,请参见例如此处: 如何在 WebStart 下调试?
回答by mkoeller
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:
手动启动 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
回答by Marco Montel
You can also provide the debug parameter to the javaws executable using the -J option
您还可以使用 -J 选项为 javaws 可执行文件提供调试参数
Example:
例子:
javaws.exe -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 http://server:port/descriptor.jnlp
回答by Nicholas Sushkin
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:
要在 Linux 中调试 Web Start 应用程序,请创建一个 shell 脚本 ~/bin/javaws-debug.sh,并在调试模式下调用 javaws,如上所述:
~/bin/javaws-debug.sh:
~/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.
然后,在您的浏览器中,选择该脚本作为对 jnlp 文件调用的应用程序。
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.
例如,在 Firefox 中,转到 Edit→Preferences→Applications,Content Type:Java Web Start,然后在 Action 中选择“Use Other”并从“Select Helper Application”对话框中选择脚本。在 Chrome 中,您需要更改 Linux 系统设置。在 KDE 中,转到系统设置→文件关联,已知类型:application:x-java-jnlp-file,添加一个新应用程序,从“选择应用程序/x-java 应用程序”中选择 ~/bin/javaws-debug.sh -jnlp-file”对话框。
Once your browser is configured, Java Web Start application will start using your wrapper, which will enable debugger to connect on port 8989.
配置浏览器后,Java Web Start 应用程序将开始使用您的包装器,这将使调试器能够连接到端口 8989。
回答by Vojtěch T?ma
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.
至于较新版本的 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
开始出现在控制台输出中。
The only solution that worked for me was to pass those arguments into JAVA_TOOL_OPTIONS system variable.
对我有用的唯一解决方案是将这些参数传递给 JAVA_TOOL_OPTIONS 系统变量。
回答by qwertzguy
With Java 8 and Windows 10, open command prompt (cmd.exe) and type this:
对于 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
回答by lmiguelmh
You will need to do the following:
您需要执行以下操作:
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 Homefrom 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
启用用于调试 Java 的参数(可选但有用,即 tls/ssl 握手问题为 close_notify 或 handshake_failure)并启动 JNLP,您可以通过两种方式执行此操作:
2.a. 下载 JNLP 文件并从命令行执行它(
SET
在这种特殊情况下不需要该命令)。set JAVA_TOOL_OPTIONS=-Djavax.net.debug=all javaws -wait jnlp.jnlp
2.b.
-Djavax.net.debug=all
在 Java 控制面板 > Java > 视图中为 JVM添加参数(即)(这在此特定情况下不需要),并从浏览器启动 JNLP 文件:日志和跟踪位于Java 部署主页的
log
目录中,我从中粘贴了以下位置:一种。视窗 XP:
%HOME%\Application Data\Sun\Java\Deployment
湾 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.
使用 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:
回答by Jorduino
You can run your JNLP with debugging enabled:
您可以在启用调试的情况下运行 JNLP:
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
输出: 侦听地址为 5009 的传输 dt_socket
Attach to this with your favorite IDE, I use IntelliJ IDEA Run>Attach to process
用你最喜欢的IDE附加到这个,我使用IntelliJ IDEA Run>Attach来处理