1、在后台持续运行jar并不输出日志到控制台(-Dlogback.configurationFile=用于给Build Artifacts打包的单独生成jar指定logback.xml日志配置,非maven打出jar包)
nohup java -Xmx2g -Xms512m -Xmn512m -Xss256k -Dlogback.configurationFile=config/logback.xml -jar jar包名称.jar 1>/dev/null 2>&1 &
2、停止对应具体名称的jar包
ps -ef | grep java > find.log
findedString=`grep "jar包名称.jar" find.log`
export pid=-999
OLD_IFS="$IFS"
IFS=","
arr=($findedString)
IFS="$OLD_IFS"
result=()
index=0
for s in ${arr[@]}
do
result[index]=$s
((index++))
done
pid=${result[1]}
if [ $pid -gt 0 ]
then
kill -9 $pid
echo "pid with jar包名称.jar killed!"
else
echo "no pid with jar包名称.jar exist!"
fi