Spring boot 打jar包分離lib的正確配置方式
前言
Springboot 打jar包分離lib,配置文件的方式,網(wǎng)上可以搜到的我都沒試通。跟劉大神(大神沒有博客,很可惜)討論后,給出了這么一個解決方案,供大家參考。
部署環(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
運行jar
java -jar -Dloader.path=.,3rd-lib test-0.0.1-SNAPSHOT-classes.jar
總結(jié)
以上所述是小編給大家介紹的Spring boot 打jar包分離lib的正確配置方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Java 數(shù)據(jù)結(jié)構(gòu)之刪除鏈表中重復(fù)的結(jié)點
在一個排序的鏈表中,會存在重復(fù)的結(jié)點,如何實現(xiàn)刪除該鏈表中重復(fù)的結(jié)點,重復(fù)的結(jié)點不保留,并返回鏈表頭指針呢?接下來小編將帶你詳細(xì)介紹2021-12-12
Jmeter連接Mysql數(shù)據(jù)庫實現(xiàn)過程詳解
這篇文章主要介紹了Jmeter連接Mysql數(shù)據(jù)庫實現(xiàn)過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-08-08
SpringBoot一個接口多個實現(xiàn)類的調(diào)用方式總結(jié)
這篇文章主要介紹了SpringBoot一個接口多個實現(xiàn)類的調(diào)用方式,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01
Maven在Windows中的配置以及IDE中的項目創(chuàng)建(圖文教程)
這篇文章主要介紹了Maven在Windows中的配置以及IDE中的項目創(chuàng)建(圖文教程),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09
springboot使用線程池(ThreadPoolTaskExecutor)示例
大家好,本篇文章主要講的是springboot使用線程池(ThreadPoolTaskExecutor)示例,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12
Springboot輕量級的監(jiān)控組件SpringbootAdmin
這篇文章主要為大家介紹了Springboot輕量級的監(jiān)控組件SpringbootAdmin使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
java多線程編程必備volatile與synchronized深入理解
這篇文章主要介紹了java多線程編程必備volatile與synchronized的深入理解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
Spring Boot整合Mybatis Plus和Swagger2的教程詳解
這篇文章主要介紹了Spring Boot整合Mybatis Plus和Swagger2的教程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-02-02

