linux设置开启启动jar包

授予 /etc/rc.d/rc.local 文件执行权限
chmod +x /etc/rc.d/rc.local

然后我们创建启动文件 runJar.sh

#!/bin/bash
 
export JAVA_HOME=/usr/local/jdk1.8.0_171
export JRE_HOME=/usr/local/jdk1.8.0_171/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH
 
cd /home/
nohup java -jar jcmes-center-0.0.1-SNAPSHOT.jar >center.log 2>&1 &
nohup java -jar jcmes-security-login-0.0.1-SNAPSHOT.jar >login.log 2>&1 &
nohup java -jar jcmes-card-0.0.1-SNAPSHOT.jar >card.log 2>&1 

这里我们选择是以生成log的方式启动jar包。

启动几个jar 就在后边添加,注意jdk的环境变量填写正确

cd /home/ 的意思是 进入jar包目录

接下来我们赋予runJar.sh 执行权限

chmod +x /home/runJar.sh
最关键的步骤

运行命令

vi /etc/rc.d/rc.local
编辑 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
/home/runJar2.sh

注意最后一行 加入我们的启动文件

最后 重启服务器

[root@localhost ~]# reboot
我们看是否已经启动

[root@localhost ~]# ps -ef | grep java
root        917      1 48 23:40 ?        00:00:11 java -jar jcmes-center-0.0.1-SNAPSHOT.jar
root        918      1 42 23:40 ?        00:00:09 java -jar jcmes-security-login-0.0.1-SNAPSHOT.jar
root       1091   1070  0 23:40 pts/0    00:00:00 grep --color=auto java
OK~!

你可能感兴趣的:(linux设置开启启动jar包)