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

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

问题描述

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

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

推荐答案

是的!这是您的设置方法.

Yes! Here is how you set it up.

创建远程运行配置:

  1. 运行 -> 编辑配置...
  2. 点击左上角的+"
  3. 在最左侧的窗格中选择远程"选项
  4. 选择一个名称(我命名为远程调试")
  5. 点击确定"保存:

上面的配置提供了三个只读字段.这些选项告诉 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天全站免登陆