前言
线上/测试环境代码出了问题,总是要在本地复现,然后debug,这个过程是在是不太友好,而且线上的很多数据本地没有,经常耽误好久的时间来同步数据。
那么,远程调试线上/测试环境程序就有了用武之地。
开启远程调试
java程序开启远程调试只需要在加入一些特定的jvm参数,有两种方式。
-
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=0.0.0.0:5555 -jar app.jar
-
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5555 -jar app.jar
参数说明:
- -Xdebug:JVM在DEBUG模式下工作;
- -Xrunjdwp:JVM使用(java debug wire protocol)来运行调试环境;
- transport:监听Socket端口连接方式,常用的dt_socket表示使用socket连接;
- server:y 表示当前是调试服务端,n 表示当前是调试客户端;
- suspend:y 表示暂停直到有调试客户端接入,n 表示启动时不中断;
- address:暴露的调试连接端口,默认值为 8000;
客户端远程调试
1)配置IDEA
2)运行Debug