經過maven-assembly-plugin將Springboot項目打包成tar.gz壓縮包,在Linux環境可執行腳本直接安裝成系統服務

  一、在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>

 

 

 二、新增release.xml

  在依賴配置中的descriptor標籤中定義了一個release.xml文件路徑,assembly則經過該配置文件,肯定打包的文件類型及其所包含的文件spring

 

<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>

   三、添加腳本文件

  腳本文件的做用是爲了在Linux環境下可直接運行進行服務的安裝,因此須要事先將腳本編輯完成apache

  四、打包

 執行mvn clean package -Dmaven.test.skip=true命令,在target目錄生成文件,解壓後,裏面包含bin、conf、lib、logs這四個目錄,在release.xml中能夠找到對應的配置,以及存放的數據與項目文件的對應關係,都在release.xml中進行設置app

 

  五、項目連接

  百度雲:https://pan.baidu.com/s/1zi1zuKTeZHs8BBjYUxm1fg 密碼:rkpcmaven

相關文章
相關標籤/搜索