1. java工程下的pom需要增加配置如下,主要是executable修改为true:
 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>
  1. 将文件进行打包即可
mvn package -Dmaven.test.skip=true
  1. 创建系统自启动文件,map.service是需要创建的服务名称
sudo vim /etc/systemd/system/map.service
  1. 在第3步创建的文件中写入如下内容,注意需要填写的路径是java所在的路径和项目jar包的存放路径
[Unit]
Description=apps
After=syslog.target
[Service]
WorkingDirectory=/home/deploy/xxpt/map/
Restart=always
Type=simple
ExecStart=/usr/bin/java -jar /home/deploy/xxpt/map/map.jar
[Install]
WantedBy=multi-user.target
  1. systemctl常用命令的记录
重新写入配置文件 systemctl daemon-reload
查看服务状态 systemctl status test
设置为开机自启动 systemctl enable test
启动服务 systemctl start test         
停止服务 systemctl stop test            
重新加载 systemctl reload test
当前项目路径 pwd
查看java所在路径 which java