Operation steps for remote debug of java program: package, upload, start, configure, debug
1. Program packaging:
For example maven package: clean package -Dmaven.test.skip=true -Pdev
2. Upload:
rz command, upload the packaged package to the linux server
3. Start:
Use the following command to start the program uploaded to the server:
java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8199 -cp jpda.jar {full path of the class where the main method is located}
tomcat start:
1.Linxu system: Add the following content to the beginning of apach/bin/startup.sh:
declare -x CATALINA_OPTS="-server -Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8788"
or add the last line of apache/bin/startup.sh :
exec "$PRGDIR"/"$EXECUTABLE" start "$@"
修改成:exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
2. Windows system: Add the following content to the beginning of apach/bin/startup.bat:
SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8788
3. Start tomcat: startup.sh jpda start
4. Check whether the specified port is up: netstat -an | grep 8000
Result: tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN
4. Configuration:
Right-click debug as >> debug Configurations >> select Remote Java Application >> click the new launch configurations icon in the upper left corner >> select the project you just packaged in the project box on the right >> host: remote server address, which is the server IP uploaded above >> port: address in the startup command above
5. Debug/debug:
然后启动这个configuration,则会连接到这个端口,如上配置完后调试开始了,首先,在eclipse中启动上面配置好的debug,设好断点,然后,访问刚才上传到服务器的项目,就可以像本地debug一样的操作了.
注意: eclipse中的项目要与上传到服务器的项目保持一致(完全一样),否则断点会偏离
注意访问的是上传到服务器上面的项目,不是访问本地项目,只是断点设在本地项目中.
此时再查看端口监听IP,会发现已经不是0.0.0.0了!