最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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,感覺如果多個(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里沒有pom里的依賴-->
                    <includes>
                        <include>
                            <groupId>null</groupId>
                            <artifactId>null</artifactId>
                        </include>
                    </includes>
                    <layout>ZIP</layout>
                    <!--使用外部配置文件,jar包里沒有資源文件-->
                    <addResources>true</addResources>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <!--配置jar包特殊標(biāo)識 配置后,保留原文件,生成新文件 *-run.jar -->
                            <!--配置jar包特殊標(biāo)識 不配置,原文件命名為 *.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的啟動圖標(biāo)了。。。

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

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

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

關(guān)閉問題解決,但啟動會報(bào):

nohup: ignoring input and redirecting stderr to stdout

再搜,前輩又指出:

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

解釋如下:

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

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

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

于是我的啟動命令改為:

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

完美解決

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

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

相關(guān)文章

  • java實(shí)現(xiàn)飯店點(diǎn)菜系統(tǒng)

    java實(shí)現(xiàn)飯店點(diǎn)菜系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)飯店點(diǎn)菜系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • SpringBoot使用LibreOffice實(shí)現(xiàn)高保真Word轉(zhuǎn)PDF的方法

    SpringBoot使用LibreOffice實(shí)現(xiàn)高保真Word轉(zhuǎn)PDF的方法

    本文介紹了在SpringBoot中使用LibreOffce實(shí)現(xiàn)高保真Word轉(zhuǎn)PDF的方法,首先詳細(xì)說明了Windows、Mac、Linux系統(tǒng)及Docker環(huán)境下LibreOffice的安裝步驟和常見問題解決方案,需要的朋友可以參考下
    2026-02-02
  • 一篇文章大家徹底學(xué)會Java之格式化輸出

    一篇文章大家徹底學(xué)會Java之格式化輸出

    Java提供了多種格式化輸出的方式,包括String.format()、System.out.printf()和Formatter類,這些方法支持?jǐn)?shù)字、日期、字符串等多種格式化操作,這篇文章主要介紹了Java格式化輸出的相關(guān)資料,需要的朋友可以參考下
    2025-04-04
  • 教你如何把Eclipse創(chuàng)建的Web項(xiàng)目(非Maven)導(dǎo)入Idea

    教你如何把Eclipse創(chuàng)建的Web項(xiàng)目(非Maven)導(dǎo)入Idea

    這篇文章主要介紹了教你如何把Eclipse創(chuàng)建的Web項(xiàng)目(非Maven)導(dǎo)入Idea,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-04-04
  • struts1之簡單mvc示例_動力節(jié)點(diǎn)Java學(xué)院整理

    struts1之簡單mvc示例_動力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要介紹了struts1之簡單mvc示例的相關(guān)資料,需要的朋友可以參考下
    2017-09-09
  • JavaWeb Spring依賴注入深入學(xué)習(xí)

    JavaWeb Spring依賴注入深入學(xué)習(xí)

    這篇文章主要為大家詳細(xì)介紹了JavaWeb Spring依賴注入,深入學(xué)習(xí)Spring依賴注入,感興趣的小伙伴們可以參考一下
    2016-09-09
  • JAVA多線程并發(fā)下的單例模式應(yīng)用

    JAVA多線程并發(fā)下的單例模式應(yīng)用

    單例模式應(yīng)該是設(shè)計(jì)模式中比較簡單的一個(gè),也是非常常見的,但是在多線程并發(fā)的環(huán)境下使用卻是不那么簡單了,今天給大家分享一個(gè)我在開發(fā)過程中遇到的單例模式的應(yīng)用。
    2017-03-03
  • struts升級到2.5.2遇到的問題及解決方案(推薦)

    struts升級到2.5.2遇到的問題及解決方案(推薦)

    原來的版本是2.3.x,由于安全原因需要升級到2.5.2。但是在升級過程中遇到各種各樣的問題,下面小編給大家?guī)砹藄truts升級到2.5.2遇到的問題及解決方案,需要的朋友參考下吧
    2016-11-11
  • Spring中的FactoryBean實(shí)現(xiàn)原理詳解

    Spring中的FactoryBean實(shí)現(xiàn)原理詳解

    這篇文章主要介紹了Spring中的FactoryBean實(shí)現(xiàn)原理詳解,spring中有兩種類型的Bean,一種是普通的JavaBean,另一種就是工廠Bean(FactoryBean),這兩種Bean都受Spring的IoC容器管理,但它們之間卻有一些區(qū)別,需要的朋友可以參考下
    2024-02-02
  • Maven 項(xiàng)目生成jar運(yùn)行時(shí)提示“沒有主清單屬性”

    Maven 項(xiàng)目生成jar運(yùn)行時(shí)提示“沒有主清單屬性”

    這篇文章主要介紹了Maven 項(xiàng)目生成jar運(yùn)行時(shí)提示“沒有主清單屬性”,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03

最新評論

禹城市| 江阴市| 岑巩县| 西充县| 阿瓦提县| 宜城市| 白沙| 崇文区| 新密市| 涞水县| 惠安县| 佳木斯市| 文昌市| 鹤山市| 绵竹市| 南充市| 夏邑县| 濉溪县| 怀安县| 大庆市| 高陵县| 揭东县| 霍林郭勒市| 青铜峡市| 田林县| 偃师市| 阿图什市| 宁阳县| 徐州市| 吉隆县| 界首市| 饶平县| 外汇| 寻乌县| 江孜县| 新民市| 西华县| 简阳市| 密云县| 调兵山市| 民权县|