zoukankan      html  css  js  c++  java
  • springboot开启远程调试

    远程调试maven设置

    The run goal forks a process for the boot application. It is possible to specify jvm arguments to that forked process. The following configuration suspend the process until a debugger has joined on port 5005

    <project>
      ...
      <build>
        ...
        <plugins>
          ...
          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.1.12.RELEASE</version>
            <configuration>
              <jvmArguments>
                -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
              </jvmArguments>
            </configuration>
            ...
          </plugin>
          ...
        </plugins>
        ...
      </build>
      ...
    </project>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    These arguments can be specified on the command line as well, make sure to wrap that properly, that is:

    mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
    • 1

    jar 命令开启远程调试

    在执行jar的时候,添加上参数。如下:

    java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar demo.jar
    • 1

    如果想深入了解Java调试,那么去看一下这个吧。深入Java调试体系

    问题

    如果出现Connection refused

    首先检查一下端口8000的使用情况:

    use:~/tomcat/logs # netstat -an|grep 8000
    cp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN
    • 1
    • 2

    可见当前16808端口服务被绑定了回环地址,外部无法访问。即本地调试。

    办法:

    修改catalina.sh中一个参数。

    if [ -z "$JPDA_TRANSPORT" ]; then
        JPDA_TRANSPORT="dt_socket"
      fi
      if [ -z "$JPDA_ADDRESS" ]; then
        JPDA_ADDRESS="0.0.0.0:8000"
      fi
      if [ -z "$JPDA_SUSPEND" ]; then
        JPDA_SUSPEND="n"
      fi
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    JPDA_ADDRESS="localhost:8000" 把默认值(localhost:8000)改成0.0.0.0:8000。默认是本地ip调试也就是无法远程调试,0.0.0.0表示所有ip地址都能调试。

    远程连上后再看端口情况:

    root@VM-198-217-ubuntu:/opt/apache-tomcat-8.5.16/bin# netstat -an | grep 8000
    tcp        0      0 10.133.198.217:8000     60.177.99.27:49998      ESTABLISHED
    • 1
    • 2

    断开后是这样的:

    root@VM-198-217-ubuntu:/opt/apache-tomcat-8.5.16/bin# netstat -an | grep 8000
    tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN
    tcp        0      0 10.133.198.217:8000     60.177.99.27:49998      TIME_WAIT
    • 1
    • 2
    • 3

    idea连接远程端口进行远程debug

    我已经在服务器上开启了远程调试,idea连接的步骤,直接上图。

    1. edit configurations

      edit configurations

    2. 远程调试配置 
      远程调试配置

    3. 参数配置 
      参数配置

      将红框内的地址和端口号改成自己的。

      参数配置

    4. 启动远程调试 
      启动远程调试

    5. 成功界面

      成功界面

    6. 请求一下试试

      试试

    转自:https://blog.csdn.net/wsyw126/article/details/74853680

  • 相关阅读:
    Python算术运算符
    Python数据类型转换
    Linux下Tomcat启动设置debug模式启动
    FastJson之JsonObject, JsonString, JavaBean,List快速转换
    Linux 之 ./configure --prefix 命令
    JS中Ajax的同步和异步
    MySql 中 case when then else end 的用法
    Linux中CentOS6.5 64位 系统下安装docker步骤
    Linux常用命令 查找文件
    微信小程序中事件
  • 原文地址:https://www.cnblogs.com/duanxz/p/4669774.html
Copyright © 2011-2022 走看看