前言:本文主要介绍一种,在使用spring boot进行项目开发的时候,往往需要将服务部署在linux服务器上,这个高效的懒人打包工具就应运而生
1.打包文件
先介绍一下该工具生成的文件内容:
- erip-router-server.zip:打包以后生成的文件,里面包含了bin、config、lib以及logs
- bin:里面包含了start.sh(启动项目),stop.sh(关闭项目),restart.sh(重启项目)
- config:里面是application的配置以及logback日志的配置
- lib:里面把该服务的jar包以及所依赖的jar包放在了里面
- logs:该文件夹用于放置启动命令日志以及服务日志
2.spring boot配置
- start.sh、stop.sh、restart.sh放在项目的src/bin目录下
- daemon-linux-zip.xml放在src/main/assembly目录下
- banner.txt放在src/main/resources/config目录下
如下图:
3.pom文件
<build>
<finalName>sznsh-business-server</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.2.0.RELEASE</version>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>zhangxin</groupId>
<artifactId>zhangxin</artifactId>
</include>
</includes>
<mainClass>com.egoonet.business.Application</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<!-- 打包插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.plugin.version}</version>
<executions>
<execution>
<id>make-daemon-linux-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<outputDirectory>${project.build.directory}</outputDirectory>
<descriptors>
<descriptor>src/main/assembly/daemon-linux-zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
pom文件应用在build打包的地方,我们只需要把application的主类配置正确即可。
4.banner.txt
,==.---------.
( ) ====== \
|| | [1][2][3] |
,6|| | [4][5][6] |
6 || | [7][8][9] |
6 ( ) * 0 # /
'66`=='--------'EGOOPS
${Ansi.GREEN} :: SZNSH BUSINESS Server For PLATFORM v1.0.0 ::${Ansi.DEFAULT}
5.效果图
本文所依赖的文件都已经打包成资源了,对该种方式有兴趣的方式,请在本页最上方移步下载