Ubuntu设置开机启动jar包java项目

1./etc/init.d/下新建脚本 autoJar.sh 名字任意
2.一定要在命令上加上这段否则报错

#!/bin/sh
### BEGIN INIT INFO
# Provides:          autoJar.sh
# Required-start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the svnd.sh daemon
# Description:       starts svnd.sh using start-stop-daemon
### END INIT INFO
export JAVA_HOME=/usr/lib/jdk/jdk1.8
export PATH=${JAVA_HOME}/bin:$PATH
cd /usr/printer
java -jar zwpp-0.0.1-SNAPSHOT.jar &

3.设置文本权限,否则不生效

$ sudo chmod 755 /etc/init.d/autoJar.sh 

4.将命令脚本添加到启动脚本中去

$ cd /etc/init.d
$ sudo update-rc.d svnd.sh defaults 90

注:90代表启动脚本的先后顺序
5.reboot重启生效测试
6.卸载启动脚本

$ cd /etc/init.d
$ sudo update-rc.d -f autoJar.sh remove
发布了47 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_37460672/article/details/92841026