将IntelliJ IDEA调试器附加到正在运行的Java进程 [英] Attach IntelliJ IDEA debugger to a running Java process

查看:542
本文介绍了将IntelliJ IDEA调试器附加到正在运行的Java进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将IntelliJ IDEA调试器附加到正在运行的Java进程?如果是,怎么办?

Is it possible to attach the IntelliJ IDEA debugger to a running Java process? If yes, how?

推荐答案

是!

创建远程运行配置:


  1. 运行->编辑配置...

  2. 单击左上方的 +

  3. 在最左侧窗格中选择远程选项

  4. 选择一个名称(我将其命名为 remote-debugging)

  5. 单击确定进行保存:

  1. Run -> Edit Configurations...
  2. Click the "+" in the upper left
  3. Select the "Remote" option in the left-most pane
  4. Choose a name (I named mine "remote-debugging")
  5. Click "OK" to save:

以上配置提供了三个只读字段。这些选项告诉JVM在运行应用程序时打开端口5005进行远程调试。将适当的一项添加到要调试的应用程序的JVM选项中。一种可能的方式是这样的:

The configuration above provides three read-only fields. These are options that tell the JVM to open up port 5005 for remote debugging when running your application. Add the appropriate one to the JVM options of the application you are debugging. One way you might do this would be like so:

export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"

但这取决于您如何运行应用程序。如果不确定三者中哪一个适合您,请从第一个开始,然后向下浏览列表,直到找到适合的一个。

But it depends on how your run your application. If you're not sure which of the three applies to you, start with the first and go down the list until you find the one that works.

您可以更改 suspend = n suspend = y 强制您的应用程序等待,直到您与IntelliJ连接之后才能启动。如果要在应用程序启动时遇到断点,这将很有帮助。

You can change suspend=n to suspend=y to force your application to wait until you connect with IntelliJ before it starts up. This is helpful if the breakpoint you want to hit occurs on application startup.

以通常,然后在IntelliJ中选择新配置并点击调试。

Start your application as you would normally, then in IntelliJ select the new configuration and hit 'Debug'.

IntelliJ将连接到JVM并启动远程调试。

IntelliJ will connect to the JVM and initiate remote debugging.

您现在可以在需要的地方通过向代码添加断点来调试应用程序。该应用程序的输出将仍然显示在以前的任何位置,但是您的断点将出现在IntelliJ中。

You can now debug the application by adding breakpoints to your code where desired. The output of the application will still appear wherever it did before, but your breakpoints will hit in IntelliJ.

这篇关于将IntelliJ IDEA调试器附加到正在运行的Java进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆