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

SpringBoot項(xiàng)目導(dǎo)出jar包及瘦身部署方式

 更新時(shí)間:2024年07月11日 09:38:45   作者:wszhlzjl  
今天項(xiàng)目要求Nginx+jar包運(yùn)行多個(gè)項(xiàng)目,在此記錄一下部署的過(guò)程,其中借鑒了好多網(wǎng)上前輩的經(jīng)驗(yàn),感謝各位的無(wú)私分享

SpringBoot項(xiàng)目使用mvn命令導(dǎo)出可運(yùn)行jar包

這部分主要是Pom.xml文件的配置,而且主要是<build></build>部分的配置。

我的springboot版本是2.1.4

1、導(dǎo)出包含lib依賴包的可執(zhí)行jar包

<build>
        <plugins>
            <!--<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>-->
            <!-- 編譯插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <mainClass>${start-class}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- 打包插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <!--<appendAssemblyId>false</appendAssemblyId>-->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!-- 主程序入口類 -->
                            <mainClass>cn.zh.demo01.Demo01Application</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <!--<id>make-assembly</id>-->
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

導(dǎo)出這個(gè)包大小為27M,感覺(jué)如果多個(gè)項(xiàng)目都這樣就太占空間了。

所以才有了下面的瘦身。

因?yàn)槎鄠€(gè)項(xiàng)目使用lib依賴包都差不多。

2、導(dǎo)出lib目錄與jar包分離的可運(yùn)行jar

    <build>
        <plugins>
            <!--<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>-->
            <!-- 編譯插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <!--重寫包含依賴,包含不存在的依賴,jar里沒(méi)有pom里的依賴-->
                    <includes>
                        <include>
                            <groupId>null</groupId>
                            <artifactId>null</artifactId>
                        </include>
                    </includes>
                    <layout>ZIP</layout>
                    <!--使用外部配置文件,jar包里沒(méi)有資源文件-->
                    <addResources>true</addResources>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <!--配置jar包特殊標(biāo)識(shí) 配置后,保留原文件,生成新文件 *-run.jar -->
                            <!--配置jar包特殊標(biāo)識(shí) 不配置,原文件命名為 *.jar.original,生成新文件 *.jar -->
                            <!--<classifier>run</classifier>-->
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- 打包插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <!--不打包資源文件-->
                    <!--<excludes>-->
                    <!--<exclude>*.**</exclude>-->
                    <!--<exclude>*/*.xml</exclude>-->
                    <!--</excludes>-->
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!--MANIFEST.MF 中 Class-Path 加入前綴-->
                            <classpathPrefix>lib/</classpathPrefix>
                            <!-- 主程序入口類 -->
                            <mainClass>cn.zh.demo01.Demo01Application</mainClass>
                        </manifest>
                        <!--<manifestEntries>-->
                        <!--&lt;!&ndash;MANIFEST.MF 中 Class-Path 加入資源文件目錄&ndash;&gt;-->
                        <!--<Class-Path>./resources/</Class-Path>-->
                        <!--</manifestEntries>-->
                    </archive>
                </configuration>
            </plugin>
            <!--拷貝依賴 copy-dependencies-->
            <!--也可以執(zhí)行mvn copy-dependencies 命令打包依賴-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
                <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>

        </plugins>
    </build>

導(dǎo)出后,lib文件目錄就有26M,我的項(xiàng)目jar包只有幾百K,不錯(cuò)!

部署及運(yùn)行

運(yùn)行命令:java -Dloader.path="lib/" -jar XXXX.jar

loader.path為lib目錄的路徑。

到此又看到springboot的啟動(dòng)圖標(biāo)了。。。

但一旦關(guān)閉SSH連接,服務(wù)就自動(dòng)停止了。

于是又上網(wǎng)搜,前輩指出:

nohup java -jar XXX.jar >log.out &;
nohup是保證ssh連接關(guān)閉后,jar任然運(yùn)行的關(guān)鍵
& 相當(dāng)于后臺(tái)運(yùn)行,你后面還可以輸入命令
 >log.out  是輸出日志的地方
ps aux|grep XXX.jar 查看某jar包的運(yùn)行的進(jìn)程號(hào)

關(guān)閉問(wèn)題解決,但啟動(dòng)會(huì)報(bào):

nohup: ignoring input and redirecting stderr to stdout

再搜,前輩又指出:

把后面的 “&” 改成 “2>&1 &”,于是把啟動(dòng)命令改成如下:

解釋如下:

2>
表示把標(biāo)準(zhǔn)錯(cuò)誤(stderr)重定向,標(biāo)準(zhǔn)輸出(stdout)是1。

尖括號(hào)后面可以跟文件名,或者是&1, &2,分別表示重定向到標(biāo)準(zhǔn)輸出和標(biāo)準(zhǔn)錯(cuò)誤。

2> &1
1> &2
2> stderr.log
1> stdout.log

于是我的啟動(dòng)命令改為:

nohup java -Dloader.path="../lib/" -jar demo01-0.0.1-SNAPSHOT.jar >log.out 2>&1 &

完美解決

關(guān)于Nginx的代理配置,可以上網(wǎng)搜一下,很多前輩的分享,在此不多說(shuō)了!

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解決java啟動(dòng)時(shí)報(bào)線程占用報(bào)錯(cuò):Exception?in?thread?“Thread-14“?java.net.BindException:?Address?already?in?use:?bind

    解決java啟動(dòng)時(shí)報(bào)線程占用報(bào)錯(cuò):Exception?in?thread?“Thread-14“?java.ne

    這篇文章主要給大家介紹了關(guān)于解決java啟動(dòng)時(shí)報(bào)線程占用:Exception?in?thread?“Thread-14“?java.net.BindException:?Address?already?in?use:?bind的相關(guān)資料,文中將解決的辦法介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • Spring Boot異常處理靜止trace

    Spring Boot異常處理靜止trace

    這篇文章主要介紹了Spring Boot異常處理靜止trace,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • SpringCloud?Bus組件的使用配置詳解

    SpringCloud?Bus組件的使用配置詳解

    bus稱之為springcloud中消息總線,主要用來(lái)在微服務(wù)系統(tǒng)中實(shí)現(xiàn)遠(yuǎn)端配置更新時(shí)通過(guò)廣播形式通知所有客戶端刷新配置信息,避免手動(dòng)重啟服務(wù)的工作,這篇文章主要介紹了SpringCloud?Bus組件的使用,需要的朋友可以參考下
    2022-03-03
  • Springboot使用切面功能詳解

    Springboot使用切面功能詳解

    Spring?Boot?是一個(gè)基于Spring框架的項(xiàng)目,它簡(jiǎn)化了基于Spring的應(yīng)用開(kāi)發(fā),這篇文章主要介紹了?Spring?Boot?中的切面功能,需要的可以了解下
    2025-01-01
  • Springboot集成規(guī)則引擎Drools方式

    Springboot集成規(guī)則引擎Drools方式

    這篇文章主要介紹了Springboot集成規(guī)則引擎Drools方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • Java隨機(jī)數(shù)的5種獲得方法(非常詳細(xì)!)

    Java隨機(jī)數(shù)的5種獲得方法(非常詳細(xì)!)

    這篇文章主要給大家介紹了關(guān)于Java隨機(jī)數(shù)的5種獲得方法,在實(shí)際開(kāi)發(fā)中產(chǎn)生隨機(jī)數(shù)的使用是很普遍的,所以在程序中進(jìn)行產(chǎn)生隨機(jī)數(shù)操作很重要,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-10-10
  • springboot項(xiàng)目idea熱部署的教程詳解

    springboot項(xiàng)目idea熱部署的教程詳解

    這篇文章主要介紹了springboot項(xiàng)目idea熱部署,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • SpringBoot整合Swagger和Actuator的使用教程詳解

    SpringBoot整合Swagger和Actuator的使用教程詳解

    Swagger 是一套基于 OpenAPI 規(guī)范構(gòu)建的開(kāi)源工具,可以幫助我們?cè)O(shè)計(jì)、構(gòu)建、記錄以及使用 Rest API。本篇文章主要介紹的是SpringBoot整合Swagger(API文檔生成框架)和SpringBoot整合Actuator(項(xiàng)目監(jiān)控)使用教程。感興趣的朋友一起看看吧
    2019-06-06
  • java使用內(nèi)存數(shù)據(jù)庫(kù)ssdb的步驟

    java使用內(nèi)存數(shù)據(jù)庫(kù)ssdb的步驟

    這篇文章主要介紹了java使用內(nèi)存數(shù)據(jù)庫(kù)ssdb的步驟,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2020-12-12
  • 分享Spring?Cloud?OpenFeign?的五個(gè)優(yōu)化技巧

    分享Spring?Cloud?OpenFeign?的五個(gè)優(yōu)化技巧

    這篇文章主要分享的是Spring?Cloud?OpenFeign?的五個(gè)優(yōu)化技巧,OpenFeign?是?Spring?官方推出的一種聲明式服務(wù)調(diào)用和負(fù)載均衡組件,更多相關(guān)內(nèi)容需要的小伙伴可以參考一下
    2022-05-05

最新評(píng)論