在jar包目录下创建一个文件,后缀为 .sh
#!/bin/bash # stop service pid=`ps -ef | grep "jar包名字" | grep -v "tail" | grep -v "grep" | awk '{print $2}'` if [ "$pid" ];then echo "pid is $pid" kill -9 "$pid" else echo "server already stopped!" fi nohup java -jar jar包名字.jar &
把jar包名字替换成自己实际的即可,这是nohup是后台启动ja包