Springboot如何基于assembly服務(wù)化實(shí)現(xiàn)打包
(1)首先我們編輯 assembly.xml 配置文件,在前文的基礎(chǔ)上新增第三方依賴設(shè)置(高亮部分),實(shí)現(xiàn)將第三方的 jar 包添加到壓縮包里的 lib 目錄:
<?xml version="1.0" encoding="UTF-8"?> <assembly> <!-- 必須寫,否則打包時(shí)會(huì)有 assembly ID must be present and non-empty 錯(cuò)誤 這個(gè)名字最終會(huì)追加到打包的名字的末尾,如項(xiàng)目的名字為 hangge-test-0.0.1-SNAPSHOT, 則最終生成的包名為 hangge-test-0.0.1-SNAPSHOT-bin.tar.gz --> <id>bin</id> <!-- 打包的類型,如果有N個(gè),將會(huì)打N個(gè)類型的包 --> <formats> <!-- <format>tar.gz</format>--> <format>zip</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <!--第三方依賴設(shè)置--> <dependencySets> <dependencySet> <!-- 不使用項(xiàng)目的artifact,第三方j(luò)ar不要解壓,打包進(jìn)zip文件的lib目錄 --> <useProjectArtifact>false</useProjectArtifact> <outputDirectory>lib</outputDirectory> <unpack>false</unpack> </dependencySet> </dependencySets> <!--文件設(shè)置--> <fileSets> <!-- 0755->即用戶具有讀/寫/執(zhí)行權(quán)限,組用戶和其它用戶具有讀寫權(quán)限; 0644->即用戶具有讀寫權(quán)限,組用戶和其它用戶具有只讀權(quán)限; --> <!-- 將src/main/assembly/bin目錄下的所有文件輸出到打包后的bin目錄中 --> <fileSet> <directory>src/main/assembly/bin</directory> <outputDirectory>bin</outputDirectory> <fileMode>0755</fileMode> <!--如果是腳本,一定要改為unix.如果是在windows上面編碼,會(huì)出現(xiàn)dos編寫問題--> <lineEnding>unix</lineEnding> <filtered>true</filtered><!-- 是否進(jìn)行屬性替換 --> </fileSet> <!-- 將src/main/assembly/config目錄下的所有文件輸出到打包后的config目錄中 --> <fileSet> <directory>src/main/assembly/config</directory> <outputDirectory>config</outputDirectory> <fileMode>0644</fileMode> </fileSet> <!-- 將src/main/resources下配置文件打包到config目錄 --> <fileSet> <directory>src/main/resources</directory> <outputDirectory>./config</outputDirectory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> <include>**/*.yml</include> </includes> <filtered>true</filtered><!-- 是否進(jìn)行屬性替換 --> </fileSet> <!-- 將項(xiàng)目啟動(dòng)jar打包到lib目錄中 --> <fileSet> <directory>target</directory> <outputDirectory>./</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> <!-- 將項(xiàng)目說明文檔打包到docs目錄中 --> <!-- <fileSet> <directory>.</directory> <outputDirectory>./docs</outputDirectory> <includes> <include>*.md</include> </includes> <fileMode>0644</fileMode> </fileSet>--> <fileSet> <directory>docs</directory> <outputDirectory>./docs</outputDirectory> <fileMode>0644</fileMode> </fileSet> <fileSet> <directory>src/main/assembly/docs</directory> <outputDirectory>./docs</outputDirectory> <fileMode>0644</fileMode> </fileSet> </fileSets> </assembly>
(2)接著編輯項(xiàng)目的 pom.xml 文件,先前使用的是 spring-boot-maven-plugin 來打包,這個(gè)插件會(huì)將項(xiàng)目所有的依賴打入項(xiàng)目 jar 包里面。我們將其替換為 maven-jar-plugin,并進(jìn)行相關(guān)設(shè)置
<build> <plugins> <!-- 指定啟動(dòng)類,將依賴打成外部jar包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <!-- 生成的jar中,不要包含pom.xml和pom.properties這兩個(gè)文件 --> <addMavenDescriptor>false</addMavenDescriptor> <manifest> <!-- 是否要把第三方j(luò)ar加入到類構(gòu)建路徑 --> <addClasspath>true</addClasspath> <!-- 外部依賴jar包的最終位置 --> <!-- 因?yàn)槲覀儗⒌谌絡(luò)ar和本項(xiàng)目jar放在同一個(gè)目錄下,這里就使用./ --> <classpathPrefix>./lib</classpathPrefix> <!-- 項(xiàng)目啟動(dòng)類 --> <mainClass>com.yuehang.disneyland.DisneylandApplication</mainClass> </manifest> </archive> </configuration> </plugin> <plugin> <!--主要使用的是maven提供的assembly插件完成--> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.1</version> <configuration> <descriptors> <!--具體的配置文件--> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <!--綁定到maven操作類型上--> <phase>package</phase> <!--運(yùn)行一次--> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
然后打包出來的結(jié)構(gòu)
運(yùn)行就ok了
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java啟動(dòng)參數(shù)(-,?-X,?-XX參數(shù))的使用
本文主要介紹了Java啟動(dòng)參數(shù)(-,?-X,?-XX參數(shù))的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06SpringBoot獲取配置文件的簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于SpringBoot如何獲取配置文件的簡(jiǎn)單實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05SpringBoot整合Redis實(shí)現(xiàn)熱點(diǎn)數(shù)據(jù)緩存的示例代碼
這篇文章主要介紹了SpringBoot中整合Redis實(shí)現(xiàn)熱點(diǎn)數(shù)據(jù)緩存,本文以IDEA?+?SpringBoot作為?Java中整合Redis的使用?的測(cè)試環(huán)境,結(jié)合實(shí)例代碼給大家詳細(xì)講解,需要的朋友可以參考下2023-03-03spring使用ehcache實(shí)現(xiàn)頁面緩存示例
這篇文章主要介紹了spring使用ehcache實(shí)現(xiàn)頁面緩存示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02springboot themaleaf 第一次進(jìn)頁面不加載css的問題
這篇文章主要介紹了springboot themaleaf 第一次進(jìn)頁面不加載css的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10IDEA2020.2.3中創(chuàng)建JavaWeb工程的完整步驟記錄
這篇文章主要給大家介紹了關(guān)于IDEA2020.2.3中創(chuàng)建JavaWeb工程的完整步驟,文中通過圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12IDEA集成JProfiler11可視化工具的詳細(xì)流程(安裝、集成、測(cè)試)
小編打算在IDEA中集成一下JProfiler11(現(xiàn)在有12版本了)工具,到網(wǎng)上搜都沒有找到合適的,于是自己動(dòng)手寫個(gè),關(guān)于IDEA集成JProfiler11可視化工具(安裝、集成、測(cè)試)相關(guān)知識(shí)感興趣的朋友一起看看吧2021-06-06