在 Glassfish 中运行的远程调试 Java Web 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10484595/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 01:15:19  来源:igfitidea点击:

Remote debugging Java web app running in Glassfish

javajakarta-eenetbeansglassfish

提问by user489041

I have a web application. It is currently deployed on a remote server in a Glassfish instance. Is it possible to remotely connect to the server and debug the application (like I would a normal java application) using Netbeans?

我有一个网络应用程序。它目前部署在 Glassfish 实例中的远程服务器上。是否可以使用 Netbeans 远程连接到服务器并调试应用程序(就像我调试普通的 Java 应用程序一样)?

If someone has done this and could provide insight or could point me to a guide, that would be great.

如果有人这样做并且可以提供见解或可以为我指出指南,那就太好了。

I know this functionality exists with Visual Studio and ASP.Net. I was not sure if there is a java equivalent.

我知道 Visual Studio 和 ASP.Net 存在此功能。我不确定是否有 Java 等价物。

Most examples that I have seen online are for applications that are simply running on a remote machine or for debugging a Glassfish application running on the local machine.

我在网上看到的大多数示例都是用于简单地在远程机器上运行的应用程序或用于调试运行在本地机器上的 Glassfish 应用程序。

回答by Edward Samson

Yes, it is possible.

对的,这是可能的。

Once you have GlassFish running in debug mode, go to the Debugmenu in NetBeans and click on Attach Debugger..., which brings up the Attachdialog. You'll probably go with something like:

在调试模式下运行 GlassFish 后,转到NetBeans 中的“调试”菜单并单击“附加调试器...”,这会显示“附加”对话框。您可能会使用以下内容:

Debugger: Java Debugger (JPDA)

Connector: SocketAttach

Transport: dt_socket

Host: hostname_or_ip_address

Port: 9009

调试器:Java 调试器 (JPDA)

连接器:SocketAttach

传输:dt_socket

主机:hostname_or_ip_address

端口:9009

Timeoutmay be left blank. When you click OKon this dialog, you should be able to connect your NetBeans debugger to GlassFish.

超时可以留空。在此对话框中单击“确定”后,您应该能够将 NetBeans 调试器连接到 GlassFish。

Remember:

记住:

  1. The firewall on your remote server (and any gateways in between) should allow connections to the debugger port (9009 in my example).
  2. Make sure you're using matching port numbers. In the GlassFish admin console, usually at: http://localhost:4848
  3. Expand Configurations.
  4. Expand server-config(or whichever you are using).
  5. Click JVM Settings.
  6. Check Debugto Enabled.
  7. Verify that Debug Optionscontains:
    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009
  1. 远程服务器上的防火墙(以及中间的任何网关)应该允许连接到调试器端口(在我的示例中为 9009)。
  2. 确保您使用的是匹配的端口号。在 GlassFish 管理控制台中,通常位于:http://localhost:4848
  3. 展开配置
  4. 展开server-config(或您使用的任何一个)。
  5. 单击JVM 设置
  6. 选中DebugEnabled
  7. 验证调试选项是否包含:
    -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009

Read the JPDA docsfor other options you can use.

阅读JPDA 文档以了解您可以使用的其他选项。