将Intellij-IDEA调试器附加到正在运行的java进程中。

时间:2022-06-04 00:52:56

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

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

4 个解决方案

#1


249  

Yes! Here is how you set it up.

是的!这是你的设置方法。

Run Configuration

Create a Remote run configuration:

创建远程运行配置:

  1. Run -> Edit Configurations...
  2. 运行- >编辑配置…
  3. Click the "+" in the upper left
  4. 点击左上方的“+”。
  5. Select the "Remote" option in the left-most pane
  6. 在最左边的窗格中选择“远程”选项。
  7. Choose a name (I named mine "remote-debugging")
  8. 选择一个名称(我命名为“远程调试”)
  9. Click "OK" to save:
  10. 单击“OK”保存:

将Intellij-IDEA调试器附加到正在运行的java进程中。

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:

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

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.

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

Debug

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

像往常一样启动应用程序,然后在IntelliJ中选择新配置并点击“Debug”。

将Intellij-IDEA调试器附加到正在运行的java进程中。

IntelliJ will connect to the JVM and initiate remote debugging.

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

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中出现。

#2


35  

It's possible, but you have to add some JVM flags when you start your application.

这是可能的,但是在启动应用程序时必须添加一些JVM标志。

You have to add remote debug configuration: Edit configuration -> Remote.

您必须添加远程调试配置:Edit configuration -> remote。

Then you'lll find in displayed dialog window parametrs that you have to add to program execution, like:

然后,您将在显示的对话框窗口中找到您必须添加到程序执行的参数,比如:

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

Then when your application is launched you can attach your debugger. If you want your application to wait until debugger is connected just change suspend flag to y (suspend=y)

然后,当您的应用程序启动时,您可以附加您的调试器。如果您希望您的应用程序等待直到调试器被连接,那么将挂起的标志挂起至y(挂起=y)

#3


4  

Obviously you need to add "-Xdebug" flag in app JAVA_OPTS if you want connect in debug mode.

显然,如果想在调试模式下连接,需要在app JAVA_OPTS中添加“-Xdebug”标志。

#4


3  

in AndroidStudio or idea

在AndroidStudio或想法

  1. Config the application will be debug, open Edit Configurations
  2. 配置应用程序将是调试,打开编辑配置。

add "VM Options" Config “-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005” remember "address"

添加“VM选项”配置“-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005”记住“地址”。

将Intellij-IDEA调试器附加到正在运行的java进程中。

  1. Config Remote Debugger if not exits, Click + to add
  2. 配置远程调试器,如果没有退出,请单击+添加。

specify "Port" same as in Step 1 "address" 将Intellij-IDEA调试器附加到正在运行的java进程中。

指定“端口”与第1步“地址”相同

#1


249  

Yes! Here is how you set it up.

是的!这是你的设置方法。

Run Configuration

Create a Remote run configuration:

创建远程运行配置:

  1. Run -> Edit Configurations...
  2. 运行- >编辑配置…
  3. Click the "+" in the upper left
  4. 点击左上方的“+”。
  5. Select the "Remote" option in the left-most pane
  6. 在最左边的窗格中选择“远程”选项。
  7. Choose a name (I named mine "remote-debugging")
  8. 选择一个名称(我命名为“远程调试”)
  9. Click "OK" to save:
  10. 单击“OK”保存:

将Intellij-IDEA调试器附加到正在运行的java进程中。

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:

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

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.

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

Debug

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

像往常一样启动应用程序,然后在IntelliJ中选择新配置并点击“Debug”。

将Intellij-IDEA调试器附加到正在运行的java进程中。

IntelliJ will connect to the JVM and initiate remote debugging.

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

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中出现。

#2


35  

It's possible, but you have to add some JVM flags when you start your application.

这是可能的,但是在启动应用程序时必须添加一些JVM标志。

You have to add remote debug configuration: Edit configuration -> Remote.

您必须添加远程调试配置:Edit configuration -> remote。

Then you'lll find in displayed dialog window parametrs that you have to add to program execution, like:

然后,您将在显示的对话框窗口中找到您必须添加到程序执行的参数,比如:

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

Then when your application is launched you can attach your debugger. If you want your application to wait until debugger is connected just change suspend flag to y (suspend=y)

然后,当您的应用程序启动时,您可以附加您的调试器。如果您希望您的应用程序等待直到调试器被连接,那么将挂起的标志挂起至y(挂起=y)

#3


4  

Obviously you need to add "-Xdebug" flag in app JAVA_OPTS if you want connect in debug mode.

显然,如果想在调试模式下连接,需要在app JAVA_OPTS中添加“-Xdebug”标志。

#4


3  

in AndroidStudio or idea

在AndroidStudio或想法

  1. Config the application will be debug, open Edit Configurations
  2. 配置应用程序将是调试,打开编辑配置。

add "VM Options" Config “-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005” remember "address"

添加“VM选项”配置“-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005”记住“地址”。

将Intellij-IDEA调试器附加到正在运行的java进程中。

  1. Config Remote Debugger if not exits, Click + to add
  2. 配置远程调试器,如果没有退出,请单击+添加。

specify "Port" same as in Step 1 "address" 将Intellij-IDEA调试器附加到正在运行的java进程中。

指定“端口”与第1步“地址”相同