# 后端代码的远程调试

## 一、服务器上添加配置

jvm是支持远程调试的，得在启动脚本里加jvm参数开启远程调试

![添加配置](/files/-Loy2nVG1BlmbDFvGaIA)

添加内容：-Xdebug -Xrunjdwp:transport=dt\_socket,address=6666,server=y,suspend=n

```
"%~dp0jvm\windows\bin\java" -Xdebug -Xrunjdwp:transport=dt_socket,address=6666,server=y,suspend=n -Xms2g -XX:+UseConcMarkSweepGC -jar "%~dp0console.jar"
```

## 二、启动服务器

正常启动服务器，但是可以看到输出的日志中有打印开放端口的的日志。

Listening for transport dt\_socket at address: 6666

![服务器启动截图](/files/-LpCoFPM5hFwCNVJ5z3C)

## 三、IDEA相关配置

### 1、增加调试/运行配置

![](/files/-Loy3xfLdezBiavV9C9T)

### 2、启动调试

点击左上角的绿色小虫，会提示

Connected to the target VM, address: '127.0.0.1:6666', transport: 'socket'

![](/files/-Loy57Jrtx4_wY7cb-0L)

### 3、增加断点

![](/files/-Loy5ta8qr04sgmQqW7u)

## 四、Eclipse相关配置

### 1、打开调试/运行配置界面

![](/files/-Lp1tdAlsB5jdtDSnVKM)

### 2、新增远程调试配置

![](/files/-Lp1u0L9EAzS_m47F99u)

### 3、选择需要调试的项目

选择项目，输入远程服务器的主机ip地址与端口号

![](/files/-Lp1uG9S74RBU8OMrdwm)

### 4、配置完成后点击“debug”按钮

![](/files/-Lp1uXGxbtXpwDvynQfu)

### 5、在代码增加断点调试

![](/files/-Lp1ufbUNlYl_qiCZfZj)

Eclipse远程调试教程很多，可以参考:

<https://www.eclipse.org/jetty/documentation/current/enable-remote-debugging.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://o2oa.gitbook.io/course/yuan-ma-de-bian-yi-ji-guan-li/cheng-xu-tiao-shi/hou-duan-kai-fa.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
