java 调试 JNLP 启动的应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10899675/
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
Debugging JNLP started application
提问by Lukas Knuth
I created a Java desktop-application (using Swing) and am now trying to make it work by starting it from the net using JNLP. The application works fine when I start it from the terminal, but as soon as I launch it from JNLP, it does not close. I have to manually kill the process every time.
我创建了一个 Java 桌面应用程序(使用 Swing),现在正在尝试通过使用 JNLP 从网络启动它来使其工作。当我从终端启动它时,该应用程序工作正常,但是一旦我从 JNLP 启动它,它就不会关闭。我每次都必须手动终止该进程。
I read that there might be a problem if my JFrame
uses DISPOSE_ON_CLOSE
as the default close-operation, but it doesn't. It uses DO_NOTHING_ON_CLOSE
(implicitly). Also, I'm explicitly calling System.exit(0)
after releasing all my objects:
我看,有可能是,如果我的问题JFrame
用途DISPOSE_ON_CLOSE
为默认关闭操作,但事实并非如此。它使用DO_NOTHING_ON_CLOSE
(隐式)。此外,我System.exit(0)
在释放所有对象后显式调用:
f = new JFrame("Pacman");
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Terminate the Game-loop:
GameLoop.INSTANCE.stopLoop();
// Close the application:
System.exit(0);
}
});
I guess that there might be an exception thrown when I close the application, but I can't find a way to get the console-output (e.g. the Stack-Trace) of a running application started with JNLP. Here's what I tried:
我猜我关闭应用程序时可能会抛出异常,但是我找不到一种方法来获取以 JNLP 启动的正在运行的应用程序的控制台输出(例如堆栈跟踪)。这是我尝试过的:
- Start
javaws
with the debugging parameters and connect withjconsole
(works but I can't find any exception- or console-ouput). - Start
javaws
with the debugging parameters and attach IntelliJ debugger to it (also works but does not give me any output)
- 从
javaws
调试参数开始并连接jconsole
(有效,但我找不到任何异常或控制台输出)。 - 从
javaws
调试参数开始并将 IntelliJ 调试器附加到它(也可以工作但不给我任何输出)
So, how can I start the application with JNLP and get the output (written to the default out- and error-streams), as if I would do with a normal desktop application?
那么,如何使用 JNLP 启动应用程序并获取输出(写入默认输出和错误流),就像使用普通桌面应用程序一样?
回答by npe
Solution #1 - Enable Java Console, and look for exceptions.
解决方案 #1 - 启用 Java 控制台,并查找异常。
You can do it via Java Control Panel. Switch to Advancedtab, and in the Java Consolemake sure Show consoleis selected.
您可以通过Java 控制面板来完成。切换到高级选项卡,并在Java 控制台中确保选择了显示控制台。
Then, run your application and monitor the console for exceptions. Fix the exception.
然后,运行您的应用程序并监视控制台是否有异常。修复异常。
Solution #2 - Debug your running application (properly).
解决方案#2 - 调试您正在运行的应用程序(正确)。
Start the Web Start app like this (for Java 1.6 and newer):
像这样启动 Web Start 应用程序(对于 Java 1.6 和更新版本):
javaws -verbose -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8123 http://myserver.com/path/to/myapp.jnlp
If using earlier java versions (1.4.2, 1.5) set the environment variable, like this:
如果使用较早的 Java 版本(1.4.2、1.5),请设置环境变量,如下所示:
set JAVAWS_VM_ARGS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=8123"
and run the app via:
并通过以下方式运行应用程序:
javaws http://myserver.com/path/to/myapp.jnlp
When the app runs:
当应用程序运行时:
- Attach a debugger (Eclipse will do - use Run=> Debug Configurations=> Remote Java Application, and in Connection Propertiespanel enter the port passed in the parameters to
javaws
(in this case:8123
). - Set a breakpoint inside your
windowClosing
method. - Try to close your application - Eclipse should break the execution on your breakpoint
- Step intothe
GameLoop.INSTANCE.stopLoop()
method to see where/when it hangs.
- 附加一个调试器(Eclipse 会做 - 使用Run=> Debug Configurations=> Remote Java Application,并在Connection Properties面板中输入传入参数的端口
javaws
(在本例中:)8123
。 - 在你的
windowClosing
方法中设置一个断点。 - 尝试关闭您的应用程序 - Eclipse 应该在您的断点处中断执行
- 进入该
GameLoop.INSTANCE.stopLoop()
方法以查看它挂起的位置/时间。
Don't expect to see a solutions in the console, just step through the code with a debugger - if the application hangs, it will show you where.
不要期望在控制台中看到解决方案,只需使用调试器单步执行代码 - 如果应用程序挂起,它会显示您在哪里。
回答by lmiguelmh
There are times when even the console doesn't show anything, for example when there is a problem with the TLS/SSL handshake (i.e. a close_notify or handshake_failure). In these cases you need to do the following:
有时甚至控制台也不显示任何内容,例如当 TLS/SSL 握手出现问题时(即 close_notify 或 handshake_failure)。在这些情况下,您需要执行以下操作:
Enable the Java logs and tracing in the Java Control Panel > Advanced.
Enable parameters for debugging Java & 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 和启动 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
回答by Manuel Romeiro
This answer is an alternative to npe answerto enable the remote debug (Windows).
此答案是启用远程调试 (Windows) 的npe 答案的替代方法。
- Go to Control Panel;
- Click on Java, to open Java Control Panel;
- Inside of Java Control Panel, go to Java tab, and click "View";
- This will open a window with installed java versions. On runtime parameters put "-Xdebug -Xrunjdwp:transport=dt_socket,address=8123,server=y,suspend=n"(if you want to debug when application is starting, change to "suspend" to "y", that will make the application stop until an editor connect remotly);
- 进入控制面板;
- 点击 Java,打开 Java 控制面板;
- 在 Java 控制面板中,转到 Java 选项卡,然后单击“查看”;
- 这将打开一个安装了 Java 版本的窗口。在运行时参数上放置“-Xdebug -Xrunjdwp:transport=dt_socket,address=8123,server=y,suspend=n”(如果要在应用程序启动时调试,将“挂起”更改为“y”,这将使应用程序停止,直到编辑器远程连接);
Afer that, configure you editor to debug remotely to the configured port (localhost:8123 in this case).
之后,将编辑器配置为远程调试到配置的端口(在本例中为 localhost:8123)。