SpringBoot如何實(shí)現(xiàn)分離資源文件并打包
Spring Boot項(xiàng)目默認(rèn)的會(huì)打包成單一的jar文件,但是有時(shí)候我們并不想讓配置文件、依賴包都跟可執(zhí)行文件打包到一起。這時(shí)候可以在pom.xml文件中進(jìn)行配置,從而使資源文件、依賴包和可執(zhí)行文件分離。
這樣子更新代碼的時(shí)候 我們的jar包很少改變 有利于維護(hù)
pom.xml 如下
<build> <plugins> <plugin> <!--打包時(shí)去除第三方依賴--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration><layout>ZIP</layout><includes> <include> <groupId>non-exists</groupId> <artifactId>non-exists</artifactId> </include></includes> </configuration> </plugin> <!--拷貝第三方依賴文件到指定目錄--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions><execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!--target/lib是依賴jar包的輸出目錄,根據(jù)自己喜好配置--> <outputDirectory>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration></execution> </executions> </plugin> </plugins></build>
記得將 項(xiàng)目resource 復(fù)制一份到同級(jí)目錄下
java -jar -Dloader.path=resources,lib (可執(zhí)行的jar包名稱).jar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python實(shí)現(xiàn)讀取類別頻數(shù)數(shù)據(jù)畫水平條形圖案例2. python中PyQuery庫(kù)用法分享3. python操作數(shù)據(jù)庫(kù)獲取結(jié)果之fetchone和fetchall的區(qū)別說明4. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫特效5. 使用css實(shí)現(xiàn)全兼容tooltip提示框6. Python編寫nmap掃描工具7. JavaScript實(shí)現(xiàn)組件化和模塊化方法詳解8. .NET6打包部署到Windows Service的全過程9. ASP動(dòng)態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享10. ASP.NET MVC前臺(tái)動(dòng)態(tài)添加文本框并在后臺(tái)使用FormCollection接收值
