Spring boot 打jar包分離lib的正確配置方式
前言
Springboot 打jar包分離lib,配置文件的方式,網(wǎng)上可以搜到的我都沒試通。跟劉大神(大神沒有博客,很可惜)討論后,給出了這么一個(gè)解決方案,供大家參考。
部署環(huán)境
- window 10
- redhat 6.4
- 其他版本沒有嘗試,應(yīng)該也是可以的
POM.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.elvish</groupId> <artifactId>test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>test</name> <description>test</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath /> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <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> <outputDirectory>target/lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>false</stripVersion> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <excludes> <exclude>**/*.properties</exclude> <exclude>**/*.xml</exclude> <exclude>**/*.yml</exclude> <exclude>static/**</exclude> <exclude>templates/**</exclude> </excludes> </configuration> </plugin> <plugin> <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> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <classifier>classes</classifier> <attach>false</attach> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <property name="dist">target/distribution</property> <property name="dist-tmp">target/distribution/tmp</property> <property name="app-name">${project.artifactId}-${project.version}</property> <mkdir dir="${dist-tmp}" /> <copy file="target/${app-name}.jar" tofile="${dist-tmp}/${app-name}.jar" /> <unzip src="${dist-tmp}/${app-name}.jar" dest="${dist-tmp}" /> <delete file="${dist-tmp}/${app-name}.jar" /> <zip destfile="${dist}/${app-name}-pages.jar"> <zipfileset dir="${dist-tmp}/META-INF" prefix="META-INF" /> <zipfileset dir="target/classes/static" prefix="static" /> <zipfileset dir="target/classes/templates" prefix="templates" /> </zip> <move file="target/${app-name}-classes.jar" todir="${dist}" /> <move todir="${dist}/3rd-lib"> <fileset dir="target/lib" /> </move> <delete dir="${dist-tmp}" /> <copy todir="${dist}"> <fileset dir="target/classes"> <include name="**/*.properties" /> <include name="**/*.xml" /> <include name="**/*.yml" /> </fileset> </copy> </target> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
打完包后目錄結(jié)構(gòu)
- 3rd-lib
- META-INF
- *.yml
- *.xml
- *.properties
- test-0.0.1-SNAPSHOT-classes.jar
- test-0.0.1-SNAPSHOT-pages.jar
運(yùn)行jar
java -jar -Dloader.path=.,3rd-lib test-0.0.1-SNAPSHOT-classes.jar
總結(jié)
以上所述是小編給大家介紹的Spring boot 打jar包分離lib的正確配置方式,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
spring security CSRF防護(hù)的示例代碼
這篇文章主要介紹了spring security CSRF防護(hù)的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-03-03Gradle構(gòu)建基本的Web項(xiàng)目結(jié)構(gòu)
這篇文章主要為大家介紹了Gradle創(chuàng)建Web項(xiàng)目基本的框架結(jié)構(gòu)搭建,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-03-03ssm框架controller層返回json格式數(shù)據(jù)到頁面的實(shí)現(xiàn)
這篇文章主要介紹了ssm框架controller層返回json格式數(shù)據(jù)到頁面的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09Mybatis-plus的selectPage()分頁查詢不生效問題解決
本文主要介紹了Mybatis-plus的selectPage()分頁查詢不生效問題解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01Java使用PrepareStatement實(shí)現(xiàn)數(shù)據(jù)的插入與查詢操作
這篇文章主要為大家詳細(xì)介紹了Java如何使用PrepareStatement實(shí)現(xiàn)數(shù)據(jù)的插入與查詢操作,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2022-09-09SpringBoot靜態(tài)資源的訪問方法詳細(xì)介紹
最近在做SpringBoot項(xiàng)目的時(shí)候遇到了“白頁”問題,通過查資料對(duì)SpringBoot訪問靜態(tài)資源做了總結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-09-09BootStrap Jstree 樹形菜單的增刪改查的實(shí)現(xiàn)源碼
這篇文章主要介紹了BootStrap Jstree 樹形菜單的增刪改查的實(shí)現(xiàn)源碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02