當我們運行一個項目的時候,一般都是在本地進行debug。但是如果是一個分布式的微服務,這時候我們選擇遠程debug是我們開發的利器。
環境
apache-tomcat-8.5.16
Linux
如何啟用遠程調試
tomcat開啟遠程調試
方法
切換到你的tomcat的bin目錄/apache-tomcat-8.5.16/bin
下,執行:
./catalina.sh jpda start
執行上面的命令就可以開啟遠程debug了,如果想配置一些信息,比如端口號什么的,請參考下面的說明。
參數說明
# JPDA_TRANSPORT (Optional) JPDA transport used when the "jpda start"# command is executed. The default is "dt_socket".## JPDA_ADDRESS (Optional) Java runtime options used when the "jpda start"# command is executed. The default is localhost:8000.## JPDA_SUSPEND (Optional) Java runtime options used when the "jpda start"# command is executed. Specifies whether JVM should suspend# execution immediately after startup. Default is "n".## JPDA_OPTS (Optional) Java runtime options used when the "jpda start"# command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,# and JPDA_SUSPEND are ignored. Thus, all required jpda# options MUST be specified. The default is:## -agentlib:jdwp=transport=$JPDA_TRANSPORT,# address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND
操作說明
所以如果想修改配置,則如下操作:
在catalina.sh中進行配置:
JPDA_TRANSPORT=dt_socket JPDA_ADDRESS=5005 JPAD_SUSPEND=n
或者通過JPDA_OPTS進行配置:
JPDA_OPTS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
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>
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"
jar 命令開啟遠程調試
在執行jar的時候,添加上參數。如下:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar demo.jar
新聞熱點
疑難解答