亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

maven?springboot如何將jar包打包到指定目錄

 更新時間:2021年12月18日 15:33:06   作者:烤鴨的世界我們不懂  
這篇文章主要介紹了maven?springboot如何將jar包打包到指定目錄,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

如何將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啟動加載的機制是優(yōu)先加載jar包,再加載外部目錄,如果jar包都存在兩個地方,這樣配置就沒有意義了,每次還是得重新發(fā)布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

jar包外指定配置文件及原理

解決方案

修改maven的pom.xml文件

不拷貝資源文件

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <excludes>
            <exclude>*</exclude>
        </excludes>
        <filtering>true</filtering>
    </resource>
</resources>

修改打包方式

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <layout>ZIP</layout>
    </configuration>
</plugin>

運行

假設application.properties和application-{profile}.properties都在/tmp/temp/config,jar文件在/tmp/temp

java -Dloader.path=file:///tmp/temp/config,demo-1.0.jar -jar demo-1.0.jar

原理

對比jar包中MANIFEST.MF文件在`ZIP配置前后的區(qū)別

配置前:

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.chinaunicom.gateway.GatewayApplication

配置后:

Main-Class: org.springframework.boot.loader.PropertiesLauncher
Start-Class: com.chinaunicom.gateway.GatewayApplication

發(fā)現是類加載器變了,查看org.springframework.boot.loader包下所有加載器實現:

這里寫圖片描述

查看五個類描述:官方文檔

JarLauncher

Launcher for JAR based archives. This launcher assumes that dependency jars are included inside a /BOOT-INF/lib directory and that application classes are included inside a /BOOT-INF/classes directory.

WarLauncher

Launcher for WAR based archives. This launcher for standard WAR archives. Supports dependencies in WEB-INF/lib as well as WEB-INF/lib-provided, classes are loaded from WEB-INF/classes.

PropertiesLauncher

Launcher for archives with user-configured classpath and main class via a properties file. This model is often more flexible and more amenable to creating well-behaved OS-level services than a model based on executable jars.
Looks in various places for a properties file to extract loader settings, defaulting to application.properties either on the current classpath or in the current working directory. The name of the properties file can be changed by setting a System property loader.config.name (e.g. -Dloader.config.name=foo will look for foo.properties. If that file doesn't exist then tries loader.config.location (with allowed prefixes classpath: and file: or any valid URL). Once that file is located turns it into Properties and extracts optional values (which can also be provided overridden as System properties in case the file doesn't exist):
loader.path: a comma-separated list of directories (containing file resources and/or nested archives in .jar or .zip or archives) or archives to append to the classpath. BOOT-INF/classes,BOOT-INF/lib in the application archive are always used
loader.main: the main method to delegate execution to once the class loader is set up. No default, but will fall back to looking for a Start-Class in a MANIFEST.MF, if there is one in ${loader.home}/META-INF.

spring-boot-maven-plugin幫助

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • 最全總結SpringBean的作用域管理

    最全總結SpringBean的作用域管理

    今天給大家詳細總結了SpringBean的作用域管理,文中有非常詳細的圖文介紹以及代碼示例,對正在學習java的小伙伴們還很有幫助,需要的朋友可以參考下
    2021-05-05
  • 線程池的七大核心參數以及常用的四種線程池詳解

    線程池的七大核心參數以及常用的四種線程池詳解

    這篇文章主要介紹了線程池的七大核心參數以及常用的四種線程池使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-05-05
  • MyBatis-Plus的apply用法小結

    MyBatis-Plus的apply用法小結

    apply方法是一個非常有用的功能,apply方法允許用戶直接在QueryWrapper或LambdaQueryWrapper中添加原生SQL片段,本文就詳細的介紹一下apply方法,感興趣的可以了解一下
    2024-10-10
  • java和matlab畫多邊形閉合折線圖示例講解

    java和matlab畫多邊形閉合折線圖示例講解

    由于要將“哈密頓回路問題(TSP)”的求解中間結果表示出來,查了一下使用程序畫多邊形圖形?,F在在總結一下,這個圖是“由給定節(jié)點首尾相連的”閉合多邊形
    2014-02-02
  • idea將項目上傳到Gitee的圖文過程

    idea將項目上傳到Gitee的圖文過程

    這篇文章主要介紹了idea將項目上傳到Gitee上,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • java.sql.SQLException:?connection?holder?is?null錯誤解決辦法

    java.sql.SQLException:?connection?holder?is?null錯誤解決辦法

    這篇文章主要給大家介紹了關于java.sql.SQLException:?connection?holder?is?null錯誤的解決辦法,這個錯誤通常是由于連接對象為空或未正確初始化導致的,文中通過代碼介紹的非常詳細,需要的朋友可以參考下
    2024-02-02
  • springboot中如何去整合shrio實例分享

    springboot中如何去整合shrio實例分享

    這篇文章主要介紹了springboot中如何去整合shrio實例分享的相關資料,需要的朋友可以參考下
    2023-08-08
  • java中volatile關鍵字的作用詳解

    java中volatile關鍵字的作用詳解

    這篇文章主要介紹了java中volatile關鍵字的作用詳解,volatile可以保證,若一個線程改變了某塊內存的值,其他線程是可見的,以至于其他線程能及時更新這塊內存,需要的朋友可以參考下
    2023-09-09
  • Java簡單統(tǒng)計字符串中漢字,英文字母及數字數量的方法

    Java簡單統(tǒng)計字符串中漢字,英文字母及數字數量的方法

    這篇文章主要介紹了Java簡單統(tǒng)計字符串中漢字,英文字母及數字數量的方法,涉及java針對字符串的遍歷、編碼轉換、判斷等相關操作技巧,需要的朋友可以參考下
    2017-06-06
  • Mybatis查不到數據查詢返回Null問題

    Mybatis查不到數據查詢返回Null問題

    mybatis突然查不到數據,查詢返回的都是Null,但是 select count(*) from xxx查詢數量,返回卻是正常的。好多朋友遇到這樣的問題不知所措,下面小編通過本教程簡單給大家說明下
    2016-08-08

最新評論