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

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

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

開場(chǎng)廢話

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

現(xiàn)在大多都是springboot項(xiàng)目了,甚至大多公司使用了多模塊用于dubbo和cloud。這里主要簡(jiǎn)單講一下新手建項(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沒有依賴,打包就會(huì)沒有清單,但是我們是添加了插件的,所以原因可能出在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)文章

最新評(píng)論

建水县| 巍山| 北碚区| 信宜市| 新蔡县| 浦城县| 尉氏县| 逊克县| 闸北区| 峨眉山市| 天峨县| 新余市| 珲春市| 辉南县| 泸水县| 临清市| 尉犁县| 林西县| 溧水县| 自治县| 乌拉特后旗| 垫江县| 茂名市| 禄丰县| 石家庄市| 衡东县| 大方县| 金塔县| 连山| 闵行区| 贵溪市| 京山县| 正定县| 苏尼特右旗| 贵州省| 长汀县| 钟祥市| 邹城市| 汉川市| 新河县| 邢台市|