Maven多模塊工程Module開發(fā)(圖文教程)
使用IDEA創(chuàng)建多模塊開發(fā)
功能模塊來分module
跟java的package類似,一般是按照的功能模塊分module,比如:sso/cas/portal/activity/system,具體可根據(jù)需要
例如,在電商系統(tǒng)中如下module
--module-test-common公共部分 --module-test-picture圖片 --module-test-order訂單 --module-test-checkout購物車 --module-test-pay支付 --module-test-catory類目 --module-test-product商品 --module-test-price價(jià)格 --module-test-account賬號 ...
組織架構(gòu)分Dao/Service/Controller/Model等方式
--module-test-service --module-test-model --module-test-controller --module-test-dao --module-test-common --module-test-util --module-test-job ...
以上兩種方式都可以,現(xiàn)在更多的應(yīng)該是傾向第一種按照功能來解耦,module前期可以配置成jar,后期也可以建立獨(dú)有的頁面,獨(dú)立的站點(diǎn),通過子域名的方式訪問,各個(gè)功能模塊解耦,趨向微服務(wù)架構(gòu)
創(chuàng)建項(xiàng)目
步驟:
File –> New –> Project –> Maven
Next
填寫GroupId和ArtifactId –> Next
完成
將工程的src和其他的目錄全部刪除,只剩下pom.xml,修改pom.xml的<packageing>
File –> New –> Module,選中【Create from archetype】,選中【org.apache.maven.archetypes:maven-archetype-webapp】
如果不用快速骨架生成的方式,需要將該module的pom.xml設(shè)置為<packaging>war</packaging>
創(chuàng)建別的模塊,別的模塊使用maven-archetype-quickstart
備注:如果不用快速骨架生成的話,則pom.xml需要配置成建好`<packaging>jar</packaging>`,并且父類的parent項(xiàng)目的pom.xml需要手動(dòng)配置如下
<modules> <module>module-test-web</module> <module>module-test-common</module> <module>module-test-order</module> <module>module-test-pay</module> </modules>
子module里面配置如下:
<parent> <artifactId>module-test</artifactId> <groupId>com.nick</groupId> <version>1.0-SNAPSHOT</version> </parent>
如下圖所示:
部署多Module項(xiàng)目
Tomcat跟普通Maven項(xiàng)目類似的方式配置
根據(jù)自己的需要在每個(gè)module添加module所需要的依賴
File –> Project Stucture
點(diǎn)擊Modules,當(dāng)項(xiàng)目的JDK是1.8的時(shí)候,配置每個(gè)module的Language Level為對應(yīng)的JDK的level
Facets
- 檢查Facets右邊的【Deplyment Descriptors】,必須是指向web.xml
- 檢查Facets右邊的【W(wǎng)eb Resource Directories】,必須是選中webapp的目錄,類似普通非maven的項(xiàng)目需要指向WebRoot或者WebContent目錄
Artifacts
這個(gè)配置很重要!這個(gè)配置很重要!這個(gè)配置很重要!
沒配置之前如下:
使用源碼模式將編譯后的文件輸出到classes下面
點(diǎn)擊運(yùn)行tomcat(不會在idea上面部署普通maven非多module項(xiàng)目的請自行百度)
module也可以使用多層級的module方式,如:
module-test --- module-test-common --- module-test-platform --- --- module-test-platform-A --- --- module-test-platform-B
由上可知:
1. module-test-platform-A和module-test-platform-B的parent是module-test-platform
2. module-test-platform和module-test-common的parent是module-test
上面配置要實(shí)現(xiàn)的話,也很簡單,只需要將module-test-platform的pom.xml里面配置成<packaging>pom</packaging>
,然后module-test-platform-A和module-test-platform-B的parent都以來module-test-platform的GAV(maven三要素:groupId/artifactId/version)就行了
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Maven最佳實(shí)踐之一個(gè)好的parent依賴基礎(chǔ)
- Git和Maven的子模塊簡單實(shí)踐
- 如何將maven項(xiàng)目劃分為多個(gè)模塊
- SpringBoot+Maven 多模塊項(xiàng)目的構(gòu)建、運(yùn)行、打包實(shí)戰(zhàn)
- maven多模塊工程打包部署的方法步驟
- SpringBoot創(chuàng)建maven多模塊項(xiàng)目實(shí)戰(zhàn)代碼
- IntelliJ IDEA創(chuàng)建maven多模塊項(xiàng)目(圖文教程)
- 詳解使用Maven構(gòu)建多模塊項(xiàng)目(圖文)
- 詳解Maven 搭建spring boot多模塊項(xiàng)目(附源碼)
- Maven的聚合(多模塊)和Parent繼承
相關(guān)文章
詳解Elastic Search搜索引擎在SpringBoot中的實(shí)踐
本篇文章主要介紹了Elastic Search搜索引擎在SpringBoot中的實(shí)踐,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01Spring Boot 集成Mybatis實(shí)現(xiàn)主從(多數(shù)據(jù)源)分離方案示例
本篇文章主要介紹了Spring Boot 集成Mybatis實(shí)現(xiàn)主從(多數(shù)據(jù)源)分離方案實(shí)例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-03-03SpringBoot+MyBatis-Plus實(shí)現(xiàn)分頁功能
在SpringBoot項(xiàng)目中,結(jié)合MyBatis-Plus(簡稱MP)可以非常方便地實(shí)現(xiàn)分頁功能,MP為開發(fā)者提供了分頁插件PaginationInterceptor,只需簡單配置即可使用,本文給大家介紹了SpringBoot+MyBatis-Plus實(shí)現(xiàn)分頁功能,文中通過代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01VSCode新手教程之配置Java環(huán)境的詳細(xì)教程
這篇文章主要給大家介紹了關(guān)于VSCode新手教程之配置Java環(huán)境的詳細(xì)教程,工欲善其事必先利其器,想要工作順利我們先搭建好JAVA的開發(fā)環(huán)境,需要的朋友可以參考下2023-10-10SpringBoot項(xiàng)目中的favicon.ico圖標(biāo)無法顯示問題及解決
這篇文章主要介紹了SpringBoot項(xiàng)目中的favicon.ico圖標(biāo)無法顯示問題及解決,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01SpringBoot+JWT實(shí)現(xiàn)單點(diǎn)登錄完美解決方案
單點(diǎn)登錄是一種統(tǒng)一認(rèn)證和授權(quán)機(jī)制,指在多個(gè)應(yīng)用系統(tǒng)中,用戶只需要登錄一次就可以訪問所有相互信任的系統(tǒng),不需要重新登錄驗(yàn)證,這篇文章主要介紹了SpringBoot+JWT實(shí)現(xiàn)單點(diǎn)登錄解決方案,需要的朋友可以參考下2023-07-07