欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot打包jar中沒有主清單屬性問題

 更新時(shí)間:2023年12月01日 10:36:21   作者:橙巴布  
這篇文章主要介紹了springboot打包jar中沒有主清單屬性問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

開場廢話

不看過程的可以直接看原因和解決方案

現(xiàn)在大多都是springboot項(xiàng)目了,甚至大多公司使用了多模塊用于dubbo和cloud。這里主要簡單講一下新手建項(xiàng)目,可以運(yùn)行,但是打包沒有主清單屬性的問題。

出現(xiàn)這種問題的情況肯定不止以下的情況,

以下兩種依賴情況:

  • a.使用了spring-boot-starter-parent + 插件=打包成功
  • b.沒有使用spring-boot-starter-parent,用插件+排除=打包成功

項(xiàng)目結(jié)構(gòu)

在這里插入圖片描述

依賴1-能運(yùn)行,打包沒有清單

主pom:
    spring-boot-starter-parent
子pom:
    spring-boot-starter
    spring-boot-starter-web    

主pom文件內(nèi)容

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo</groupId>
    <artifactId>diy</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <modules>
        <module>diy-common</module>
        <module>diy-api</module>
        <module>diy-service</module>
    </modules>
</project>

service pom

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>diy</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>diy-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

依賴1-改-能運(yùn)行,打包正常

增加打包插件

主pom:
    spring-boot-starter-parent
子pom:
    spring-boot-starter
    spring-boot-starter-web
    spring-boot-maven-plugin

server pom

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>diy</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>diy-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

依賴2-能運(yùn)行,打包沒有清單

主pom中不加parent依賴,在子版本中指定springboot版本

主pom:
子pom:
    spring-boot-starter
    spring-boot-starter-web
    spring-boot-maven-plugin

主 pom

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo</groupId>
    <artifactId>diy</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>diy-common</module>
        <module>diy-api</module>
        <module>diy-service</module>
    </modules>
</project>

service pom

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>diy</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>diy-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.5.3</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.5.3</version>
            </plugin>
        </plugins>
    </build>
</project>

依賴2改-能運(yùn)行,打包正常

在spring-boot-maven-plugin插件中增加executions

主pom:
子pom:
    spring-boot-starter
    spring-boot-starter-web
    spring-boot-maven-plugin
        <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>diy</artifactId>
        <groupId>com.demo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>diy-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.5.3</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.5.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

原因分析 

使用springboot時(shí)需要使用打包插件,插件有很多,這里使用spring-boot-maven-plugin

當(dāng)我們?yōu)榱俗鑫⒎?wù)時(shí),在主pom中不增加多余的依賴時(shí),子中只能設(shè)置一個(gè)parent,就是主pom,這時(shí)spring-boot-starter-parent沒有依賴,打包就會沒有清單,但是我們是添加了插件的,所以原因可能出在spring-boot-start-parent包中。

查看spring-boot-start-parent內(nèi)容

這個(gè)pom里面添加了一個(gè)打包排除

解決方案 

使用了 spring-boot-starter-parent依賴的直接加入插件就行

沒有使用spring-boot-starter-parent依賴的,除了加插件,在插件中加個(gè)排除

<!--這里是有spring-boot-starter-parent依賴的處理-->
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
<!--這里是沒有spring-boot-starter-parent依賴的處理-->
<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--因?yàn)闆]有依賴parent,所以這里版本不能少,一般情況下和上面的starter版本一樣,或者可以低那么幾個(gè)小版本-->
                <version>2.5.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

總結(jié)

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

相關(guān)文章

  • Java 快速排序(QuickSort)原理及實(shí)現(xiàn)代碼

    Java 快速排序(QuickSort)原理及實(shí)現(xiàn)代碼

    這篇文章主要介紹了Java 快速排序(QuickSort)原理及實(shí)現(xiàn)代碼,有需要的朋友可以參考一下
    2014-01-01
  • springboot如何通過controller層實(shí)現(xiàn)頁面切換

    springboot如何通過controller層實(shí)現(xiàn)頁面切換

    在Spring Boot中,通過Controller層實(shí)現(xiàn)頁面切換背景,Spring Boot的默認(rèn)注解是@RestController,它包含了@Controller和@ResponseBody,@ResponseBody會將返回值轉(zhuǎn)換為字符串返回,因此無法實(shí)現(xiàn)頁面切換,將@RestController換成@Controller
    2024-12-12
  • java中ThreadLocal的應(yīng)用場景實(shí)例分析

    java中ThreadLocal的應(yīng)用場景實(shí)例分析

    在本篇文章里小編給大家整理的是一篇關(guān)于java中ThreadLocal的應(yīng)用場景實(shí)例分析,對此有興趣的朋友們可以學(xué)習(xí)參考下。
    2021-02-02
  • Java常用JVM參數(shù)實(shí)戰(zhàn)

    Java常用JVM參數(shù)實(shí)戰(zhàn)

    本文主要介紹了Java常用JVM參數(shù)實(shí)戰(zhàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • MyBatis傳入List集合查詢數(shù)據(jù)問題

    MyBatis傳入List集合查詢數(shù)據(jù)問題

    這篇文章主要介紹了MyBatis傳入List集合查詢數(shù)據(jù)問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • 關(guān)于在Java中如何使用yaml的實(shí)例

    關(guān)于在Java中如何使用yaml的實(shí)例

    這篇文章主要介紹了關(guān)于在Java中如何使用yaml的實(shí)例,YAML是一種輕量級的數(shù)據(jù)序列化格式。它以易讀、易寫的文本格式表示數(shù)據(jù),支持列表、字典等各種數(shù)據(jù)結(jié)構(gòu),被廣泛應(yīng)用于配置文件、數(shù)據(jù)傳輸協(xié)議等領(lǐng)域,需要的朋友可以參考下
    2023-08-08
  • Java IO讀取文件的實(shí)例詳解

    Java IO讀取文件的實(shí)例詳解

    這篇文章主要介紹了Java IO讀取文件的實(shí)例詳解的相關(guān)資料,主要介紹字符流和字節(jié)流的內(nèi)容,需要的朋友可以參考下
    2017-07-07
  • IDEA創(chuàng)建javaee項(xiàng)目依賴war exploded變紅失效的解決方案

    IDEA創(chuàng)建javaee項(xiàng)目依賴war exploded變紅失效的解決方案

    在使用IntelliJ IDEA創(chuàng)建JavaEE項(xiàng)目時(shí),可能會遇到Tomcat部署的warexploded文件出現(xiàn)問題,解決方法是首先刪除有問題的warexploded依賴,然后根據(jù)圖示重新導(dǎo)入項(xiàng)目,此外,調(diào)整虛擬路徑有時(shí)也能有效解決問題
    2024-09-09
  • SpringBoot+MybatisPlus+Mysql+Sharding-JDBC分庫分表

    SpringBoot+MybatisPlus+Mysql+Sharding-JDBC分庫分表

    本文主要介紹了SpringBoot+MybatisPlus+Mysql+Sharding-JDBC分庫分表,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Java實(shí)現(xiàn)JWT登錄認(rèn)證的示例代碼

    Java實(shí)現(xiàn)JWT登錄認(rèn)證的示例代碼

    Java中我們可以使用諸如JJWT這樣的庫來生成和驗(yàn)證JWT,本文主要介紹了Java實(shí)現(xiàn)JWT登錄認(rèn)證的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-04-04

最新評論