日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[maven] springboot将jar包打包到指定目录

發布時間:2023/12/10 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [maven] springboot将jar包打包到指定目录 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

大家好,我是烤鴨:
今天分享一下springboot將jar包打包到指定目錄下。
由于之前上線都是一個打包到一個jar,由于服務多了,1個包100多M,哪怕是小版本上線都需要重新上傳jar包。

1.目的


將不常用的比如spring,druid等不常用打包到lib目錄,這樣每次上線不需要上傳這些。第三方或者常改動的還打包到本身的jar包內,每次上線都會新打包。
這樣原來的100多M的jar包,可以變成2、3M。
如圖所示:
原來的打包方式

改后的方式:

2.修改pom


簡單解釋一下,includes標簽內就是打入jar包第三方jar。將上面的2M的包解壓縮后,就是includes的包。如圖所示。

excludeGroupIds和excludeArtifactIds 是配置不在lib目錄里的包,由于java啟動加載的機制是優先加載jar包,
再加載外部目錄,如果jar包都存在兩個地方,這樣配置就沒有意義了,每次還是得重新發布lib目錄,所以將includes
中的包,再在excludeGroupIds 和 excludeArtifactIds 配置上

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.0.5.RELEASE</version><executions><execution><goals><goal>repackage</goal><goal>build-info</goal></goals></execution></executions><configuration><layout>ZIP</layout><includes><include><groupId>nothing</groupId><artifactId>nothing</artifactId></include><include><groupId>com.etc</groupId><artifactId>etc-manage-api</artifactId></include><include><groupId>com.etc</groupId><artifactId>etc-manage-core</artifactId></include><include><groupId>com.etc</groupId><artifactId>etc-manage-rpc-api</artifactId></include><include><groupId>com.sinoiov.etc.apollo</groupId><artifactId>apollo-spring-boot-starter</artifactId></include></includes></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>copy</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><excludeGroupIds>com.sinoiov.etc.apollo</excludeGroupIds><excludeArtifactIds>etc-manage-api,etc-manage-core,etc-manage-rpc-api</excludeArtifactIds><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin></plugins> </build>

3.修改啟動腳本


原腳本

java -jar etc-manage-service-basic-2.2.0.jar

現腳本 (如果相對目錄不好用,就用絕對目錄試試)

java Dloader.path=../lib ?-jar etc-manage-service-basic-2.2.0.jar

?

總結

以上是生活随笔為你收集整理的[maven] springboot将jar包打包到指定目录的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。