JDWP远程调试

511 阅读1分钟

JDWP全称:Java Debug Wire Protocol, java调试协议

就是远程调试,比如说测试环境需要debug找问题,直接使用这种方式在本地idea中打断点连测试环境进行调试,找问题。生产环境不建议这样操作。

命令:java -agentlib:jdwp=help

                Java Debugger JDWP Agent Library

               --------------------------------



  (see http://java.sun.com/products/jpda for more information)



jdwp usage: java -agentlib:jdwp=[help]|[<option>=<value>, ...]



Option Name and Value            Description                       Default

---------------------            -----------                       -------

suspend=y|n                      wait on startup?                  y

transport=<name>                 transport spec                    none

address=<listen/attach address>  transport spec                    ""

server=y|n                       listen for debugger?              n

launch=<command line>            run debugger on event             none

onthrow=<exception name>         debug on throw                    none

onuncaught=y|n                   debug on any uncaught?            n

timeout=<timeout value>          for listen/attach in milliseconds n

mutf8=y|n                        output modified utf-8             n

quiet=y|n                        control over terminal messages    n



Obsolete Options

----------------

strict=y|n

stdalloc=y|n



Examples

--------

  - Using sockets connect to a debugger at a specific address:

    java -agentlib:jdwp=transport=dt_socket,address=localhost:8000 ...

  - Using sockets listen for a debugger to attach:

    java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y ...




Notes

-----

  - A timeout value of 0 (the default) is no timeout.




Warnings

--------

  - The older -Xrunjdwp interface can still be used, but will be removed in

    a future release, for example:

        java -Xdebug -Xrunjdwp:[help]|[<option>=<value>, ...]

看例子

使用服务端监控

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5050 -jar test-1.0.jar

配置客户端,在idea中

A6015943-5B59-4AFB-BF76-8C479E2A2BAD.png

点击+,选择Remote JVM Debug 9C1F705E-3224-40E9-8FC4-071E20DECAC4.png

E8C210A6-6459-4C33-BA7A-798BA2ECB929.png

点击ok按钮,这样就配置好了

8BBAC691-4B8C-4114-9AE9-BE1DCA0D4EC7.png

点击debug直接运行,就可以进入到断点。