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

IDEA使用Maven創(chuàng)建父與子多模塊項(xiàng)目的圖文教程

 更新時(shí)間:2025年03月05日 10:40:31   作者:pan_junbiao  
在?IntelliJ?IDEA?中使用?Maven?創(chuàng)建父與子多模塊項(xiàng)目是一個(gè)常見的開發(fā)實(shí)踐,有助于更好地組織和管理代碼,所以本文小編給大家介紹了IDEA使用Maven創(chuàng)建父與子多模塊項(xiàng)目的圖文教程,需要的小伙伴跟著小編一起來看看吧

引言

在 IntelliJ IDEA 中使用 Maven 創(chuàng)建父與子多模塊項(xiàng)目是一個(gè)常見的開發(fā)實(shí)踐,有助于更好地組織和管理代碼。在多模塊項(xiàng)目中,可以將公共的代碼、資源或配置抽離到獨(dú)立的模塊中,然后在其他模塊中直接引用。這樣可以避免代碼重復(fù),提高代碼的重用性。

父模塊可以統(tǒng)一管理依賴的版本和配置,子模塊則繼承這些配置。這樣不僅簡(jiǎn)化了依賴管理,還確保了項(xiàng)目中所有模塊使用的依賴版本一致,減少了因版本不一致導(dǎo)致的沖突和錯(cuò)誤。多模塊項(xiàng)目允許將項(xiàng)目按照功能或業(yè)務(wù)進(jìn)行分割,每個(gè)模塊都有自己的職責(zé)和功能。這使得項(xiàng)目結(jié)構(gòu)更加清晰易懂,方便開發(fā)者進(jìn)行模塊化管理。

1、創(chuàng)建父工程

(1)使用 IDEA 新建父工程。

(2)刪除父工程下多余的文件和文件夾。

2、創(chuàng)建子模塊

(1)右鍵父工程,選擇“新建”,然后選擇“新模塊”。

(2)創(chuàng)建子模塊。

分別創(chuàng)建3個(gè)子模塊:

com-pjb-proudct:商品模塊。

com-pjb-order:訂單模塊。

com-pjb-member:會(huì)員模塊。

注意:子模塊的組名(包名)必須與父工程的一致。

(3)繼續(xù)創(chuàng)建其余的子模塊

3、父工程的 Maven 配置

(1)設(shè)置父工程的包為 pom(必須)。

<!-- 設(shè)置父工程的包為 pom -->
<packaging>pom</packaging>

(2)關(guān)聯(lián)子模塊。

<!-- 關(guān)聯(lián)子模塊-->
<modules>
    <module>com-pjb-proudct</module>
    <module>com-pjb-order</module>
    <module>com-pjb-member</module>
</modules>

(3)設(shè)置 <dependencyManagement> 節(jié)點(diǎn)。

Maven 中的 <dependencyManagement>節(jié)點(diǎn),用于父工程POM中定義依賴的版本和配置,而不實(shí)際引入這些依賴。它提供了一種集中管理和控制項(xiàng)目中所有模塊或子項(xiàng)目所使用的依賴項(xiàng)版本的方式。

通過 <dependencyManagement> 節(jié)點(diǎn),可以在父POM中統(tǒng)一聲明依賴項(xiàng)的版本,子模塊在引用這些依賴時(shí)無需再顯式指定版本號(hào),從而確保所有子模塊使用的都是同一版本的依賴。

在父 POM 的 <dependencyManagement> 部分,使用 <dependencies> 元素包裹一系列的 <dependency> 元素,每個(gè) <dependency> 元素指定一個(gè)依賴項(xiàng)的 groupId、artifactId 和 version。

<properties>
    <spring.boot.version>2.4.2</spring.boot.version>
    <lombok.version>1.18.28</lombok.version>
</properties>
 
<!-- <dependencyManagement>節(jié)點(diǎn):用于父工程POM中定義依賴的版本和配置,而不實(shí)際引入這些依賴-->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring.boot.version}</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>${spring.boot.version}</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring.boot.version}</version>
        </dependency>
 
        <!-- Lombok 依賴 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>
 
    </dependencies>
</dependencyManagement>

(4)完整的父工程 pom.xml 文件配置。

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <!-- SpringBoot 的依賴-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/>
    </parent>
 
    <groupId>com.pjb</groupId>
    <artifactId>MultiModule</artifactId>
    <version>1.0.0</version>
    <name>MultiModule</name>
    <description>MultiModule</description>
 
    <!-- 設(shè)置父工程的包為 pom -->
    <packaging>pom</packaging>
 
    <!-- 關(guān)聯(lián)子模塊-->
    <modules>
        <module>com-pjb-proudct</module>
        <module>com-pjb-order</module>
        <module>com-pjb-member</module>
    </modules>
 
    <properties>
        <spring.boot.version>2.4.2</spring.boot.version>
        <lombok.version>1.18.28</lombok.version>
    </properties>
 
    <!-- <dependencyManagement>節(jié)點(diǎn):用于父工程POM中定義依賴的版本和配置,而不實(shí)際引入這些依賴-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>${spring.boot.version}</version>
            </dependency>
 
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
                <version>${spring.boot.version}</version>
            </dependency>
 
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${spring.boot.version}</version>
            </dependency>
 
            <!-- Lombok 依賴 -->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
            </dependency>
 
        </dependencies>
    </dependencyManagement>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
 
</project>

4、子模塊的 Maven 配置

(1)<parent> 節(jié)點(diǎn)引用父工程的依賴。

<!-- 步驟1:不再直接使用SpringBoot依賴,而是引用父工程的依賴-->
<parent>
    <groupId>com.pjb</groupId>
    <artifactId>MultiModule</artifactId>
    <version>1.0.0</version>
</parent>

(2)設(shè)置子模塊的包為 jar(必須)。

<!-- 步驟2:設(shè)置子模塊的包為 jar -->
<packaging>jar</packaging>

(3)完整的子模塊 pom.xml 文件配置。

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <!-- 步驟1:不再直接使用SpringBoot依賴,而是引用父工程的依賴-->
    <parent>
        <groupId>com.pjb</groupId>
        <artifactId>MultiModule</artifactId>
        <version>1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
 
    <!-- 步驟2:設(shè)置子模塊的包為 jar-->
    <packaging>jar</packaging>
 
    <!-- 注意:groupId 必須與父工程一致 -->
    <groupId>com.pjb</groupId>
    <artifactId>Proudct</artifactId>
    <version>1.0.0</version>
    <name>com-pjb-proudct</name>
    <description>com-pjb-proudct</description>
 
    <!-- 子模塊在引用這些依賴時(shí)無需再顯式指定版本號(hào),從而確保所有子模塊使用的都是父工程同一版本的依賴 -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
 
        <!-- Lombok 依賴 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
 
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- 注意:必須加上如下配置,否則打包會(huì)報(bào)錯(cuò) -->
                <configuration>
                    <classifier>exec</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>

5、啟動(dòng)服務(wù)

啟動(dòng)子模塊,測(cè)試運(yùn)行結(jié)果。

啟動(dòng)成功。

以上就是IDEA使用Maven創(chuàng)建父與子多模塊項(xiàng)目的圖文教程的詳細(xì)內(nèi)容,更多關(guān)于IDEA Maven創(chuàng)建父與子項(xiàng)目的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • MapStruct實(shí)體間轉(zhuǎn)換的簡(jiǎn)單用法

    MapStruct實(shí)體間轉(zhuǎn)換的簡(jiǎn)單用法

    今天小編就為大家分享一篇關(guān)于MapStruct實(shí)體間轉(zhuǎn)換的簡(jiǎn)單用法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • 使用Java繪制心形動(dòng)畫的代碼示例

    使用Java繪制心形動(dòng)畫的代碼示例

    Java動(dòng)態(tài)愛心代碼是一種簡(jiǎn)單而精美的動(dòng)態(tài)效果,這篇文章主要介紹了使用Java繪制心形動(dòng)畫的代碼示例,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-06-06
  • Java異常處理之try...catch...finally詳解

    Java異常處理之try...catch...finally詳解

    今天小編就為大家分享一篇關(guān)于Java異常處理之try...catch...finally詳解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • 使用Springboot實(shí)現(xiàn)word在線編輯保存

    使用Springboot實(shí)現(xiàn)word在線編輯保存

    PageOffice目前支持的Web編程語(yǔ)言及架構(gòu)有:Java(JSP、SSH、MVC等),ASP.NET(C#、VB.NET、MVC、Razor等),PHP,ASP,本篇文章就帶你使用Springboot整合PageOffice實(shí)現(xiàn)word在線編輯保存
    2021-08-08
  • Android開發(fā)在輪播圖片上加入點(diǎn)擊事件的方法

    Android開發(fā)在輪播圖片上加入點(diǎn)擊事件的方法

    這篇文章主要介紹了Android開發(fā)在輪播圖片上加入點(diǎn)擊事件的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-11-11
  • 使用Java實(shí)現(xiàn)將PowerPoint轉(zhuǎn)換為PDF的完整指南

    使用Java實(shí)現(xiàn)將PowerPoint轉(zhuǎn)換為PDF的完整指南

    將 PowerPoint 轉(zhuǎn)換為 PDF 就是一個(gè)規(guī)避兼容問題的不二選擇,通過 Java 完成這一自動(dòng)化流程,則能進(jìn)一步應(yīng)用到辦公自動(dòng)化和在線文檔系統(tǒng)中,下面我們就來看看具體實(shí)現(xiàn)步驟吧
    2025-12-12
  • Kafka利用Java實(shí)現(xiàn)數(shù)據(jù)的生產(chǎn)和消費(fèi)實(shí)例教程

    Kafka利用Java實(shí)現(xiàn)數(shù)據(jù)的生產(chǎn)和消費(fèi)實(shí)例教程

    這篇文章主要給大家介紹了關(guān)于Kafka利用Java實(shí)現(xiàn)數(shù)據(jù)的生產(chǎn)和消費(fèi)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-01-01
  • Java通過反射查看類的信息示例

    Java通過反射查看類的信息示例

    這篇文章主要介紹了Java通過反射查看類的信息,結(jié)合實(shí)例形式詳細(xì)分析了java基于反射獲取類信息的相關(guān)原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-07-07
  • java冒泡排序簡(jiǎn)單實(shí)例

    java冒泡排序簡(jiǎn)單實(shí)例

    本文主要介紹了JSONjava冒泡排序?qū)嵗c思路分析。具有一定的參考價(jià)值,下面跟著小編一起來看下吧
    2017-01-01
  • 簡(jiǎn)單了解Java中的可重入鎖

    簡(jiǎn)單了解Java中的可重入鎖

    這篇文章主要介紹了簡(jiǎn)單了解Java中的可重入鎖,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11

最新評(píng)論

驻马店市| 女性| 长岭县| 宾阳县| 宜兰市| 漳平市| 沁源县| 无锡市| 稻城县| 房产| 阿荣旗| 乾安县| 庆阳市| 紫云| 兴海县| 泸水县| 嵊泗县| 石渠县| 承德县| 嘉义县| 泸溪县| 巴彦县| 台中市| 岳阳市| 九江县| 东明县| 读书| 苍南县| 进贤县| 丹凤县| 南涧| 宝兴县| 邢台市| 泰来县| 鹤岗市| 托克逊县| 木兰县| 新绛县| 奇台县| 调兵山市| 内江市|