1、前言
在大型企業項目中,系統架構復雜多變,一個項目根本無法支撐起所有業務。為了提高項目擴展性、靈活性、重用性,封裝性,將項目分為多個Module是非常必要的。
?這里就不說IDEA如何安裝了,安裝好IDEA后需要修改maven配置settings.xml,添加阿里鏡像地址,提高maven下載依賴包速度。打開文件D:\Program Files\JetBrains\IntelliJ IDEA 2019.1\plugins\maven\lib\maven3\conf\settings.xml,找到mirrors節點,追加
<mirror><!--This sends everything else to /public --><id>nexus-aliyun</id><mirrorOf>*</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror>
?
?
2、創建parent?Module,打開已安裝好的IDEA工具,Create New Porject
?
選擇Manve,create from archetype?不需要勾選,直接next。輸入自定義的groupId和ArtfactId,點擊next。
?
?輸入project name和選擇project location,點擊finish。
?
?刪除src目錄,除了parent Module刪除src外,其實子Module都不能刪除src。
?
?創建parent?Module完成。
?
?
2、創建公用common Module,在項目上右鍵,選擇New-->Module
?
創建New Module和創建parent Module類似,不需要勾選cretate from archetype,直接next。
?
填寫groupid和artifactid,點擊next。
??
填寫相關信息finish,一般IDEA幫我們充填完成。
?
??
common Module創建完成,不需要刪除src。
?
在common項目中,右鍵java,new--packege創建com.test?等?packge
?然后在test右鍵new--java class,創建Hello class
?
創建main Module,和創建common Module一樣。
?
?
?
?引用common依賴,Ctrl+Shift+Alt+S打開下圖
?在main項目中,pom.xml需要添加common依賴
<dependencies><dependency><groupId>com.mySpring.common</groupId><artifactId>mySpringcommon</artifactId><version>1.0-SNAPSHOT</version></dependency></dependencies>
?
?
?在main項目,java目錄右鍵新建start class。import?引入Hello類。
?
?運行start類。
?
輸出結果。module調用成功。
?