<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
SpringBoot分離打Jar包的兩種方式
此方式基於這個小夥伴的設定改的:https://www.jb51.net/article/188606.htm
注意
org.springframework.boot.loader.PropertiesLauncher
maven-dependency-plugin
自動複製到 lib
目錄maven-resources-plugin
自動複製到 config
目錄-Dloader.path=lib路徑,config路徑
target/
目錄下都可以看到)config/**
:所有resources下的資原始檔lib/**
:所有lib包,包括本地依賴xxx.jar
:應用Jarjava -Dloader.path=lib,config -Dspring.profiles.active=dev -jar main.jar
簡略版設定
<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"> <properties> <!--依賴輸出目錄--> <lib-path>lib</lib-path> <!--組態檔輸出目錄--> <config-path>config</config-path> <!--jar包名稱--> <final-name>xxx</final-name> <!--指定啟動類--> <main-class>org.jeecg.JeecgSystemApplication</main-class> </properties> <build> <!--專案名稱--> <finalName>${final-name}</finalName> <plugins> <!--定義專案的編譯環境--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!--maven的測試用例外掛,建議跳過。--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!--這個是springboot的預設編譯外掛,他預設會把所有的檔案打包成一個jar--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!-- 打自定義的JAR包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <!-- MANIFEST.MF 中 Class-Path 加入字首 --> <classpathPrefix>${lib-path}/</classpathPrefix> <!-- jar包不包含唯一版本標識 --> <useUniqueVersions>false</useUniqueVersions> <!--指定入口類 --> <mainClass>${main-class}</mainClass> </manifest> <manifestEntries> <!--MANIFEST.MF 中 Class-Path 加入資原始檔目錄 --> <!--本地依賴,多個需要使用空格隔開--> <Class-Path>./${config-path}/ lib/zwdd-1.2.0.jar lib/spire-10.jar</Class-Path> </manifestEntries> </archive> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </plugin> <!-- 該外掛的作用是用於複製依賴的jar包到指定的資料夾裡 --> <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>${project.build.directory}/${lib-path}/</outputDirectory> </configuration> </execution> </executions> </plugin> <!-- 該外掛的作用是用於複製指定的檔案 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <executions> <!-- 複製組態檔 --> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <resources> <!--複製資原始檔到外部,注意這裡先不做filtering處理,防止某些靜態檔案損壞--> <resource> <filtering>false</filtering> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> </resource> <!--僅針對yml組態檔filtering處理(預留位置@@等)--> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <includes> <include>*.yml</include> </includes> </resource> </resources> <outputDirectory>${project.build.directory}/${config-path}</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> <resources> <!--包含java類路徑下的資原始檔(mybatis的xml等)--> <resource> <directory>src/main/java</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> <include>**/*.json</include> <include>**/*.ftl</include> </includes> </resource> <!--排除jar包內的所有resources組態檔--> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <excludes> <exclude>**/*</exclude> </excludes> </resource> <!--注: 為了能在IDEA中跑起來,需要將所有yml組態檔打進jar包,filtering必須開啟(處理預留位置等操作)--> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>*.yml</include> </includes> </resource> </resources> </build> </project>
完整設定(帶部分註釋)
<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"> <parent> <groupId>org.jeecgframework.boot</groupId> <artifactId>jeecg-boot-parent</artifactId> <version>2.4.0</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>jeecg-boot-module-system</artifactId> <repositories> <repository> <id>aliyun</id> <name>aliyun Repository</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <dependencies> <dependency> <groupId>com.spire</groupId> <artifactId>spire</artifactId> <version>10</version> <scope>system</scope> <systemPath>${project.basedir}/../lib/Spire.Doc.jar</systemPath> </dependency> <dependency> <groupId>com.zwdd.api</groupId> <artifactId>zwdd</artifactId> <version>1.2.0</version> <scope>system</scope> <systemPath>${project.basedir}/../lib/zwdd-sdk-java-1.2.0.jar</systemPath> </dependency> </dependencies> <properties> <!--依賴輸出目錄--> <lib-path>lib</lib-path> <!--springboot預設打包輸出目錄--> <jar-path>jar</jar-path> <!--組態檔輸出目錄--> <config-path>config</config-path> <!--jar包名稱--> <final-name>xxx</final-name> <!--指定啟動類--> <main-class>org.jeecg.JeecgSystemApplication</main-class> </properties> <build> <!--專案名稱--> <finalName>${final-name}</finalName> <plugins> <!--定義專案的編譯環境--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!--maven的測試用例外掛,建議跳過。--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin> <!--這個是springboot的預設編譯外掛,他預設會把所有的檔案打包成一個jar,注意這裡打包出來不會包含systemScope的jar包,有需要的話得在最後的resources裡設定--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <!--這裡僅展示外掛作用,直接跳過此外掛--> <skip>true</skip> <mainClass>${main-class}</mainClass> <fork>true</fork> <addResources>true</addResources> <!--指定啟用的組態檔application-xxx.yml--> <profiles>${profile.name}</profiles> <outputDirectory>${project.build.directory}/${jar-path}</outputDirectory> </configuration> </plugin> <!-- 打自定義的JAR包 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <!-- 不打包資原始檔(組態檔和依賴包分開),這裡設定的資源排除,僅在*.xml這類檔案萬用字元篩選生效,因此不在這裡處理 --> <excludes> <!--這種檔案方式匹配可以生效--> <!--<exclude>*.yml</exclude>--> <!--下面這種方式設定是無效的,見:https://stackoverflow.com/questions/4113697/in-maven-how-to-exclude-resources-from-the-generated-jar--> <!--上述問題連結中有此描述:<exclude>src/test/resources/**</exclude> doesn't work. Exclude will be applied on jar final path and should be <exclude>*.properties</exclude>--> <!--<exclude>src/main/resources/**</exclude>--> </excludes> <archive> <manifest> <addClasspath>true</addClasspath> <!-- MANIFEST.MF 中 Class-Path 加入字首 --> <classpathPrefix>${lib-path}/</classpathPrefix> <!-- jar包不包含唯一版本標識 --> <useUniqueVersions>false</useUniqueVersions> <!--指定入口類 --> <mainClass>${main-class}</mainClass> </manifest> <manifestEntries> <!--MANIFEST.MF 中 Class-Path 加入資原始檔目錄 --> <!--本地依賴,多個需要使用空格隔開--> <Class-Path>./${config-path}/ lib/zwdd-1.2.0.jar lib/spire-10.jar</Class-Path> </manifestEntries> </archive> <outputDirectory>${project.build.directory}</outputDirectory> </configuration> </plugin> <!-- 該外掛的作用是用於複製依賴的jar包到指定的資料夾裡 --> <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> <!--這裡可以手動新增構建id,但預設是全打包就不需要了--> <!--<includeArtifactIds>xxxx</includeArtifactIds>--> <!--預設包含所有scope,因此原生的依賴也正常複製--> <!--<includeScope>system</includeScope>--> <outputDirectory>${project.build.directory}/${lib-path}/</outputDirectory> </configuration> </execution> </executions> </plugin> <!-- 該外掛的作用是用於複製指定的檔案 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <executions> <!-- 複製組態檔 --> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <resources> <!--複製資原始檔到外部,注意這裡先不做filtering處理,防止某些靜態檔案損壞--> <resource> <filtering>false</filtering> <directory>src/main/resources</directory> <includes> <!--<include>*.yml</include>--> <!--把所有resources目錄下的資原始檔複製出來--> <include>**/*</include> </includes> </resource> <!--僅針對yml組態檔filtering處理(預留位置@@等)--> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> <includes> <include>*.yml</include> </includes> </resource> </resources> <outputDirectory>${project.build.directory}/${config-path}</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> <!--手動處理資原始檔,這裡的操作都是針對最終打出的jar包內部檔案的進行引入、篩選、過濾等等,預設檔案都打進jar包內部的根路徑下,因此前面的外掛[maven-jar-plugin]中需要設定相對路徑--> <!--具體路徑在這裡: /project/build/plugins/[maven-jar-plugin]/configuration/archive/manifestEntries/Class-Path 新增classpath:. (注意和其它設定以空格分開)--> <resources> <!--包含java類路徑下的資原始檔(mybatis的xml等)--> <resource> <directory>src/main/java</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> <include>**/*.json</include> <include>**/*.ftl</include> </includes> </resource> <!--排除jar包內的所有resources組態檔--> <resource> <directory>src/main/resources</directory> <!--filtering會做處理組態檔@@預留位置等操作,但是不排除某些檔案的話可能導致壓縮損壞--> <filtering>false</filtering> <excludes> <exclude>**/*</exclude> </excludes> </resource> <!--注: 上述設定已經能夠正常分離所有設定、外部依賴、工程程式碼,啟動命令:java -jar xxx.jar--> <!--注: 但是工程打包後,你會發現IDEA上跑不起來(target/classes目錄下沒有組態檔)--> <!--注: 這裡嘗試過在IDEA啟動app時指定JVM引數(但是沒有用,誰研究過可以說下): -Dloader.path=lib,config--> <!--注: 為了能在IDEA中跑起來,需要將所有yml組態檔打進jar包,filtering必須開啟(處理預留位置等操作)--> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>*.yml</include> </includes> </resource> <!--本地依賴打進jar包,這個設定是配合spring-boot-maven-plugin外掛使用的--> <!--<resource>--> <!-- <directory>../lib/crack</directory>--> <!-- <targetPath>BOOT-INF/lib/</targetPath>--> <!-- <includes><include>**/*.jar</include></includes>--> <!--</resource>--> <!--<resource>--> <!-- <directory>../lib</directory>--> <!-- <targetPath>BOOT-INF/lib/</targetPath>--> <!-- <includes><include>*.jar</include></includes>--> <!--</resource>--> </resources> </build> </project>
注意
org.springframework.boot.loader.PropertiesLauncher
maven-dependency-plugin
自動複製到 lib
目錄maven-resources-plugin
自動複製到 config
目錄-Dloader.path=lib路徑,config路徑
target/
目錄下都可以看到)config/**
:所有resources下的資原始檔lib/**
:所有lib包,包括本地依賴xxx.jar
:應用Jarjava -Dloader.path=lib,config -Dspring.profiles.active=dev -jar main.jar
設定參考
<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"> <build> <finalName>main</finalName> <plugins> <!--該外掛的作用是指定編譯設定、做預處理,如Lombok、mapstruct等框架需要預處理程式碼--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <annotationProcessorPaths> <path> <groupId>org.mapstruct</groupId> <artifactId>mapstruct-processor</artifactId> <version>1.4.1.Final</version> </path> <path> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> </path> </annotationProcessorPaths> </configuration> </plugin> <!--該外掛的作用是打包spring-boot的jar包--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!--入口其實會自動設定--> <mainClass>org.jeecg.JeecgSystemApplication</mainClass> <!--不排除的話,systemScope的依賴包會自動被此外掛打包進xxx.jarBOOT-INFlib,和外部依賴產生衝突 --> <includeSystemScope>false</includeSystemScope> <skip>false</skip> <!--分離Jar包--> <layout>ZIP</layout> <includes> <include> <groupId>nothing</groupId> <artifactId>nothing</artifactId> </include> </includes> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <!-- 該外掛的作用是複製依賴的jar包到指定的資料夾裡 --> <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>${project.build.directory}/lib/</outputDirectory> </configuration> </execution> </executions> </plugin> <!-- 該外掛的作用是複製指定的檔案 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <executions> <!-- 複製組態檔 --> <execution> <id>copy-resources</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <resources> <!--複製資原始檔到外部,注意這裡先不做filtering處理,防止某些靜態檔案損壞--> <resource> <filtering>false</filtering> <directory>src/main/resources</directory> <includes> <include>**/*</include> </includes> </resource> <!--僅針對組態檔filtering處理(預留位置@@等)--> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>*.xml</include> <include>*.yml</include> <include>*.properties</include> </includes> </resource> </resources> <outputDirectory>${project.build.directory}/config</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> <resources> <!--打包java路徑下的靜態檔案--> <resource> <directory>src/main/java</directory> <filtering>false</filtering> <includes> <include>**/*.xml</include> <include>**/*.json</include> <include>**/*.ftl</include> </includes> </resource> <!--注: 為了能在IDEA中跑起來,需要將所有yml組態檔打進jar包,filtering必須開啟(處理預留位置等操作)--> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>*.yml</include> <include>*.txt</include> </includes> </resource> </resources> </build> </project>
到此這篇關於SpringBoot分離打Jar包的兩種方式的文章就介紹到這了,更多相關SpringBoot打Jar包內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45