這篇文章主要介紹“Java項目開啟遠程調(diào)試的方法步驟”,在日常操作中,相信很多人在Java項目開啟遠程調(diào)試的方法步驟問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Java項目開啟遠程調(diào)試的方法步驟”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都網(wǎng)站制作、成都網(wǎng)站設(shè)計網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元鶴慶做網(wǎng)站,已為上家服務(wù),為鶴慶各地企業(yè)和個人服務(wù),聯(lián)系電話:13518219792環(huán)境
apache-tomcat-8.5.16
Linux
如何啟用遠程調(diào)試
tomcat開啟遠程調(diào)試
方法
切換到你的tomcat的bin目錄/apache-tomcat-8.5.16/bin
下,執(zhí)行:
./catalina.sh jpda start
執(zhí)行上面的命令就可以開啟遠程debug了,如果想配置一些信息,比如端口號什么的,請參考下面的說明。
參數(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中進行配置:
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開啟遠程調(diào)試
遠程調(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 命令開啟遠程調(diào)試
在執(zhí)行jar的時候,添加上參數(shù)。如下:
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar demo.jar
如果想深入了解Java調(diào)試,那么去看一下這個吧。深入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中一個參數(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
對JPDA_ADDRESS="localhost:8000"
把默認(rèn)值(localhost:8000)改成0.0.0.0:8000。默認(rèn)是本地ip調(diào)試也就是無法遠程調(diào)試,0.0.0.0表示所有ip地址都能調(diào)試。
遠程連上后再看端口情況:
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連接遠程端口進行遠程debug
我已經(jīng)在服務(wù)器上開啟了遠程調(diào)試,idea連接的步驟,直接上圖。
edit configurations
遠程調(diào)試配置
參數(shù)配置
將紅框內(nèi)的地址和端口號改成自己的。
啟動遠程調(diào)試
成功界面
請求一下試試
調(diào)試的姿勢和本地調(diào)試一樣,開始造起來吧!
到此,關(guān)于“Java項目開啟遠程調(diào)試的方法步驟”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
本文題目:Java項目開啟遠程調(diào)試的方法步驟-創(chuàng)新互聯(lián)
URL鏈接:http://muchs.cn/article20/cdccco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)站設(shè)計公司、域名注冊、網(wǎng)站策劃、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容