IDEA之远程调试代码
一、调试Jar包启动的程序
1、新建SpringBoot项目,创建测试的Controller
package com.zhixi.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName TestController
* @Author zhangzhixi
* @Description
* @Date 2022-12-25 15:52
* @Version 1.0
*/
@RestController
@RequestMapping("/remote")
public class TestController {
@GetMapping("/debug")
public String debug() {
int integer = 0;
for (int i = 1; i <= 100; i++) {
integer += i;
}
return Integer.toString(integer);
}
}
2、IDEA新建远程JVM调试

3、将jar包上传到服务器,使用命令启动jar包
注意:
- 服务器上防火墙要开启你的项目端口(8080),和你的调试端口(5005)
java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 remote_debug-0.0.1-SNAPSHOT.jar
4、访问测试
- 1、在idea处打断点,并且启动新建的远程JVM调试服务
- 2、浏览器访问:http://43.143.195.160:8080/remote/debug
可以看到已经成功通过debug访问到了。

二、调试Tomcat启动的程序
这里IDEA配置的方法如上,只是通过Tomcat进行部署,需要将Debug参数写到Tomcat的文件中去
编辑$TOMCAT_HOME/bin/catalina.sh,首行添加参数,然后启动IDEA调试即可
#!/bin/sh export JAVA_OPTS='agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'

浙公网安备 33010602011771号