Idea's debug debugging server springboot project
The online code needs to be the same as the local one, remember to open the server port (firewall)
1. Write a shell script to start the jar project
#!/bin/sh
# 定义变量
JAR_NAME="$2.jar"
# 监听端口
ADD_PORT="$3"
# 该方法会重新启动程序
debug() {
# 查看pid,先杀掉,再运行jar
pid=$(ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}')
# 设置默认监听端口
if [ -z $ADD_PORT ]; then
ADD_PORT="51135"
echo "......default Listen on port for DEBUG:${ADD_PORT}"
fi
# -z 表示为空
if [ ! -z $pid ]; then
kill -9 $pid
echo ""
echo "......kill -9 ${pid}....."
nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$ADD_PORT -Dloader.path=lib/ -jar $JAR_NAME >debugOut.log 2>&1 &
pid=$(ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}')
echo ""
echo "debug Service ${JAR_NAME} is starting!newPid:${pid}, Listen on port:${ADD_PORT}"
echo "......debug restart: success......"
echo ""
else
nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$ADD_PORT -Dloader.path=lib/ -jar $JAR_NAME >debugOut.log 2>&1 &
pid=$(ps -ef | grep $JAR_NAME | grep -v grep | awk '{print $2}')
echo ""
echo "debug Service ${JAR_NAME} is starting!pid:${pid}, address:${ADD_PORT}"
echo "......debug Start: success......"
echo ""
fi
}
# 根据输入参数执行对应方法
case "$1" in
"debug")
debug
;;
esac
Two, idea configuration connection
Debugger mode : Choose Attach to remote JVM
Host: The IP of your own server;
Port: Listening port, not the same as the port of the program
Command line arguments for remote JVM: Choose according to the jdk version installed by yourself
Use module classPath: Generally, idea will be automatically selected as your project name
Three, test
1. Use tools: network debugging assistant, test interface with postman is also wide
Network debugging assistant download address Password: mkd7 Netty service嘞
2. Linux run jar project
[root@kong demo]# ls
demo_logs lib demo-1.2.jar start.sh
[root@kong demo]# sh start.sh debug demo-1.2
......default Listen on port for DEBUG:51135
debug Service demo-1.2.jar is starting!pid:23084, address:51135
......debug Start: success......
[root@kong demo]#
or
[root@kong dust]# sh start.sh debug demo-1.2 12364
......kill -9 23084......
debug Service demo-1.2.28.jar is starting!newPid:23234, Listen on port:12364
......debug restart: success......
[root@kong dust]#
3. Tools and idea testing
As a little ape, do you still use Windows, then... I can't afford a mac, and using deepin is also savory! ! ! ! ! ! ! !