這篇文章主要介紹“Java項(xiàng)目開啟遠(yuǎn)程調(diào)試的方法步驟”,在日常操作中,相信很多人在Java項(xiàng)目開啟遠(yuǎn)程調(diào)試的方法步驟問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Java項(xiàng)目開啟遠(yuǎn)程調(diào)試的方法步驟”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
環(huán)境
apache-tomcat-8.5.16
Linux
如何啟用遠(yuǎn)程調(diào)試
tomcat開啟遠(yuǎn)程調(diào)試
方法
切換到你的tomcat的bin目錄/apache-tomcat-8.5.16/bin
下,執(zhí)行:
./catalina.sh jpda start
執(zhí)行上面的命令就可以開啟遠(yuǎn)程debug了,如果想配置一些信息,比如端口號(hào)什么的,請(qǐng)參考下面的說明。
參數(shù)說明
# 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中進(jìn)行配置:
JPDA_TRANSPORT=dt_socket JPDA_ADDRESS=5005 JPAD_SUSPEND=n
或者通過JPDA_OPTS進(jìn)行配置:
JPDA_OPTS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
springboot開啟遠(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
<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 命令開啟遠(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)試體系
問題
如果出現(xiàn)Connection refused
。
首先檢查一下端口8000的使用情況:
use:~/tomcat/logs # netstat -an|grep 8000cp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
可見當(dāng)前16808端口服務(wù)被綁定了回環(huá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)試也就是無法遠(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
斷開后是這樣的:
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ù)器上開啟了遠(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)試一樣,開始造起來吧!
到此,關(guān)于“Java項(xiàng)目開啟遠(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ī)砀鄬?shí)用的文章!
本文題目:Java項(xiàng)目開啟遠(yuǎn)程調(diào)試的方法步驟-創(chuàng)新互聯(lián)
URL鏈接:http://m.kartarina.com/article20/cdccco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、域名注冊(cè)、網(wǎng)站策劃、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容