1、在pom.xml中添加maven-assembly-plugin依賴,同時需將默認生成的spring-boot-maven-plugin依賴刪除,否則最終打出的發行包啟動會有問題
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <!-- not append assembly id in release file name --> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assembly/release.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin>
2、新增release.xml
在依賴配置中的descriptor標簽中定義了一個release.xml文件路徑,assembly則通過該配置文件,確定打包的文件類型及其所包含的文件
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> <id>dist</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <fileSets> <fileSet> <directory>src/main/bin</directory> <outputDirectory>bin</outputDirectory> <directoryMode>0777</directoryMode> <includes> <include>**/*</include> </includes> <fileMode>0777</fileMode> <lineEnding>unix</lineEnding> </fileSet> <fileSet> <directory>target/classes</directory> <outputDirectory>conf</outputDirectory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <excludes> <exclude>**/*.class</exclude> </excludes> </fileSet> <fileSet> <directory>target</directory> <outputDirectory>logs</outputDirectory> <excludes> <exclude>**/*</exclude> </excludes> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <unpack>false</unpack> </dependencySet> </dependencySets> </assembly>
3、添加腳本文件
腳本文件的作用是為了在Linux環境下可直接運行進行服務的安裝,所以需要事先將腳本編輯完成
4、打包
執行mvn clean package -Dmaven.test.skip=true命令,在target目錄生成文件,解壓后,里面包含bin、conf、lib、logs這四個目錄,在release.xml中可以找到對應的配置,以及存放的數據與項目文件的對應關系,都在release.xml中進行設置
5、項目鏈接
百度雲:https://pan.baidu.com/s/1zi1zuKTeZHs8BBjYUxm1fg 密碼:rkpc