新聞中心
這篇文章主要介紹“Java項(xiàng)目開(kāi)啟遠(yuǎn)程調(diào)試的方法步驟”,在日常操作中,相信很多人在Java項(xiàng)目開(kāi)啟遠(yuǎn)程調(diào)試的方法步驟問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Java項(xiàng)目開(kāi)啟遠(yuǎn)程調(diào)試的方法步驟”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來(lái),先為額爾古納等服務(wù)建站,額爾古納等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為額爾古納企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
環(huán)境
apache-tomcat-8.5.16
Linux
如何啟用遠(yuǎn)程調(diào)試
tomcat開(kāi)啟遠(yuǎn)程調(diào)試
方法
切換到你的tomcat的bin目錄/apache-tomcat-8.5.16/bin
下,執(zhí)行:
./catalina.sh jpda start
執(zhí)行上面的命令就可以開(kāi)啟遠(yuǎn)程debug了,如果想配置一些信息,比如端口號(hào)什么的,請(qǐng)參考下面的說(shuō)明。
參數(shù)說(shuō)明
# 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
操作說(shuō)明
所以如果想修改配置,則如下操作:
在catalina.sh中進(jìn)行配置:
JPDA_TRANSPORT=dt_socket JPDA_ADDRESS=5005 JPAD_SUSPEND=n
或者通過(guò)JPDA_OPTS進(jìn)行配置:
JPDA_OPTS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
springboot開(kāi)啟遠(yuǎn)程調(diào)試
遠(yuǎn)程調(diào)試maven設(shè)置
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
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 命令開(kāi)啟遠(yuǎn)程調(diào)試
在執(zhí)行jar的時(shí)候,添加上參數(shù)。如下:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar demo.jar
如果想深入了解Java調(diào)試,那么去看一下這個(gè)吧。深入Java調(diào)試體系
問(wèn)題
如果出現(xiàn)Connection refused
。
首先檢查一下端口8000的使用情況:
use:~/tomcat/logs # netstat -an|grep 8000cp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
可見(jiàn)當(dāng)前16808端口服務(wù)被綁定了回環(huán)地址,外部無(wú)法訪問(wèn)。即本地調(diào)試。
辦法:
修改catalina.sh中一個(gè)參數(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
對(duì)JPDA_ADDRESS="localhost:8000"
把默認(rèn)值(localhost:8000)改成0.0.0.0:8000。默認(rèn)是本地ip調(diào)試也就是無(wú)法遠(yuǎn)程調(diào)試,0.0.0.0表示所有ip地址都能調(diào)試。
遠(yuǎn)程連上后再看端口情況:
root@VM-198-217-ubuntu:/opt/apache-tomcat-8.5.16/bin# netstat -an | grep 8000tcp 0 0 10.133.198.217:8000 60.177.99.27:49998 ESTABLISHED
斷開(kāi)后是這樣的:
root@VM-198-217-ubuntu:/opt/apache-tomcat-8.5.16/bin# netstat -an | grep 8000tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTENtcp 0 0 10.133.198.217:8000 60.177.99.27:49998 TIME_WAIT
idea連接遠(yuǎn)程端口進(jìn)行遠(yuǎn)程debug
我已經(jīng)在服務(wù)器上開(kāi)啟了遠(yuǎn)程調(diào)試,idea連接的步驟,直接上圖。
edit configurations
遠(yuǎn)程調(diào)試配置
參數(shù)配置
將紅框內(nèi)的地址和端口號(hào)改成自己的。
啟動(dòng)遠(yuǎn)程調(diào)試
成功界面
請(qǐng)求一下試試
調(diào)試的姿勢(shì)和本地調(diào)試一樣,開(kāi)始造起來(lái)吧!
到此,關(guān)于“Java項(xiàng)目開(kāi)啟遠(yuǎn)程調(diào)試的方法步驟”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
本文標(biāo)題:Java項(xiàng)目開(kāi)啟遠(yuǎn)程調(diào)試的方法步驟
轉(zhuǎn)載來(lái)源:http://www.ef60e0e.cn/article/gpdjcj.html