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

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

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

開場廢話

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

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

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

以下兩種依賴情況:

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

項目結構

在這里插入圖片描述

依賴1-能運行,打包沒有清單

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

主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>
    <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-改-能運行,打包正常

增加打包插件

主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-能運行,打包沒有清單

主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改-能運行,打包正常

在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時需要使用打包插件,插件有很多,這里使用spring-boot-maven-plugin

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

查看spring-boot-start-parent內容

這個pom里面添加了一個打包排除

解決方案 

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

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

<!--這里是有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>
                <!--因為沒有依賴parent,所以這里版本不能少,一般情況下和上面的starter版本一樣,或者可以低那么幾個小版本-->
                <version>2.5.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

總結

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

相關文章

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

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

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

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

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

    java中ThreadLocal的應用場景實例分析

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

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

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

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

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

    關于在Java中如何使用yaml的實例

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

    Java IO讀取文件的實例詳解

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

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

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

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

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

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

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

最新評論