一、概述
系统为centos7系统
二、开机自启动jar
xilanapp.jar
三、编写脚本
文件存放位置和名字自己定义,此处为startup.sh,存放位置为jar包位置
# !/bin/bash
# program
# file preview server star
#java
export JAVA_HOME=/usr/java/jdk1.8.0_231-amd64
export PATH=${JAVA_HOME}/bin:$PATH
nohup java -jar /opt/app/xilanapp.jar >/opt/app/nohup.out 2>&1 &
chmod 777 /opt/app/nohup.out
说明:如果没有vim工具,可以使用yum install vim 即可下载,或者使用vi,系统默认自带;编辑文件时先按i建,编辑完后按esc退出,再按:wq 保存并退出
四、给startup.sh添加执行权限
chmod +x startup.sh
五、编辑rc.local文件
在rc.local文件末尾添加startup.sh文件的路径,保存退出
vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
su - root -c '/opt/app/startup.sh'
六、授予rc.local文件权限
chmod +x /etc/rc.d/rc.local
七、重启系统
reboot
八、重启后查看jar是否已启动
ps -ef |grep java