-
环境说明:
操作系统:centos 7
springboot版本:1.5.16 -
假设jar包名称为
signin-web-1.0-SNAPSHOT.jar
假设jar包名称为signin-web-1.0-SNAPSHOT.jar
-
在pom中添加如下配置,将项目打包为一个可执行jar包,无需
java -jar xx.jar
。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.3.5.RELEASE</version>
<configuration>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
- 将打包好的jar包上传,移动至/opt/目录。
- 使用
vim /etc/systemd/system/signin.service
将以下内容复制。
[Unit]
Description=signin
After=syslog.target
[Service]
User=root
ExecStart=/opt/signin-web-1.0-SNAPSHOT.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
6.systemctl enable signin.service
设置开机启动
7. systemctl start signin.service
启动项目