背景:打好jar包,并在本地运行java -jar xxx.jar无误
1、修改pom.xml中关于插件的配置信息
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
2、重新使用mvn package打包
3、在centos中注册服务
#centos6
sudo ln -s /usr/local/xxx.jar(jar包所在路径) /etc/init.d/xxx
service xxx start
service xxx stop
service xxx status
chkconfig xxx on
#日志文件存在于/var/log/xxx.log中
#centos7
1、在/etc/systemd/system/中新建文件xxx.service
2、在xxx.service中加入下面内容
[Unit]
Description=xxx
After=syslog.target
[Service]
ExecStart=/usr/bin/java -jar /usr/local/xxx.jar(jar包存放于/usr/local/xxx.jar)
[Install]
WantedBy=multi-user.target
systemctl start xxx
systemctl stop xxx
systemctl status xxx
systemctl enable xxx
#项目日志
journalctl -u xxx