原文地址:点我
一、使用maven构建springboot项目
pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.itxsl</groupId>
<artifactId>springboot</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
启动类:
package cn.itxsl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @Author itxsl
* @Description
* @Date 2018/10/8 11:03
*/
@SpringBootApplication
public class Start {
public static void main(String[] args) {
SpringApplication.run(Start.class, args);
}
}
打包该项目:
二、将springboot项目注册到linux服务
将打包后的文件上传到linux服务器中:
创建springboot.service文件:
vim /etc/systemd/system/springboot.service
文件内容如下:
[Unit]
Description=springboot service
After=syslog.target
[Service]
Type=simple
ExecStart= /root/app/jdk1.8.0_181/bin/java -jar /root/springboot/springboot-1.0-SNAPSHOT.jar
[Install]
WantedBy=multi-user.target
刷新服务配置文件:
systemctl daemon-reload
启动服务:
systemctl start springboot.service
停止服务:
systemctl stop springboot.service
查看服务状态:
systemctl status springboot.service
查看日志:
journalctl -u springboot.service