-
idea中创建remote配置
-
远程服务器上运行jar包(此次测试为web工程)
注意: 启动命令
将上面remote配置的jdk参数复制过来
java -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 demo-springboot-remote-debug-0.0.1-SNAPSHOT.jar

Intellij IDEA基于Springboot的远程调试
延伸
普通的java工程, 也可以远程debug吗?
这种需求没有应用场景, 但这里还是折腾一下.
首先, 可以想象, 一般的java工程, main方法一运行, 瞬间就停止了, 这个时候, 本地idea是来不及启动remote-debug应用的.
那我在服务器运行工程前, 先在本地启动remote-debug应用可以吗? 答案: 不行, 报错: 远程拒绝访问. 很简单, 远程没有启动程序, 也就没有开启监听远程调试端口的进程. 所以, 本地自然无法访问.
解决方案: 只要让java工程不停的运行下去就可以了.
@SpringBootApplication
public class SpringbootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
TestAppRemoteDebug testAppRemoteDebug = new TestAppRemoteDebug();
testAppRemoteDebug.run();
}
}
public class TestAppRemoteDebug {
public void run() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("test service .... ");
}
}, 100L, 3000L);
}
}

网友评论