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

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

问题描述

可以将Intellij-IDEA调试器附加到正在运行的java进程吗?

解决方案

是的!



运行配置



创建远程运行配置:


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

  2. 点击左上角的+

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

  4. 选择一个名称(我命名为远程调试)

  5. 点击确定保存:



JVM选项



上面的配置三个只读字段。这些是在运行应用程序时通知JVM打开端口5005进行远程调试的选项。将适当的一个添加到正在调试的应用程序的JVM选项中。您可能会这样做的一种方法是:

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

但这取决于运行应用程序的方式。如果您不确定这三个中的哪一个适用于您,请从第一个开始,然后从列表中下移,直到找到可用的列表。



您可以更改 suspend = n to suspend = y 强制您的应用程序等到IntelliJ启动之前连接。如果您想要点击的断点发生在应用程序启动时,这是有帮助的。



调试



启动您的应用程序您通常会在IntelliJ中选择新的配置并点击Debug。





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



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


Is it possible to attach Intellij-IDEA debugger to a running java process?

解决方案

Yes! Here is how you set it up.

Run Configuration

Create a Remote run configuration:

  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 Options

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.

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.

Debug

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

IntelliJ will connect to the JVM and initiate remote debugging.

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天全站免登陆