If you encounter a problem, just mention the permissions. There is nothing that cannot be solved by mentioning the permissions.
Create a file
carried out
sudo vi /etc/init.d/jar.sh
Open the file and add the following content, mainly JAVA_HOME, you are looking for where your jdk is, then the following three do not need to be moved. The last one is the jar package you want to start, the start statement.
export JAVA_HOME=/usr/local/jdk1.8.0_251-amd64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
sudo nohup java -Xms256m -Xmx256m -jar /home/admin/apps/test.jar> /home/admin/apps/test.log 2>&1 &
Execute sudo vi /etc/rc.d/rc.local and add the following statement
/etc/rc.d/init.d/jar.sh
Add permissions to two files, raise permissions sudo
chmod +x /etc/init.d/jar.sh
#以前有时候在rc.local中添加命令无法执行,现在回想可能是没给这个文件设置权限
chmod +x /etc/rc.d/rc.local
If it doesn’t work, change +x to a+x
Then restart the virtual machine server to automatically start the jar package!