傳統的多模塊方式是建立domain、dao、service等,這種方式是按照軟件架構進行分割,現在更多的應該是傾向按照功能來解耦,module前期可以配置成jar,后期也可以建立獨有的頁面,獨立的站點,通過子域名的方式訪問,各個功能模塊解耦,趨向微服務架構,下面就按照這種方式進行處理
一、建立公共模塊




某塊生成完畢后,修改本模塊的pom.xml,添加必要的包,由於本模塊是繼承父模塊,所以不需要在引用包上加version了
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>xframe</artifactId> 7 <groupId>xie.frame</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 12 <artifactId>xframe-common</artifactId> 13 14 <name>xframe-common</name> 15 <packaging>jar</packaging> 16 <properties> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <maven.compiler.source>1.8</maven.compiler.source> 19 <maven.compiler.target>1.8</maven.compiler.target> 20 </properties> 21 22 <dependencies> 23 <dependency> 24 <groupId>org.apache.logging.log4j</groupId> 25 <artifactId>log4j-api</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>junit</groupId> 29 <artifactId>junit</artifactId> 30 </dependency> 31 <dependency> 32 <groupId>javassist</groupId> 33 <artifactId>javassist</artifactId> 34 </dependency> 35 <dependency> 36 <groupId>org.springframework</groupId> 37 <artifactId>spring-core</artifactId> 38 </dependency> 39 <dependency> 40 <groupId>org.springframework</groupId> 41 <artifactId>spring-beans</artifactId> 42 </dependency> 43 <dependency> 44 <groupId>org.springframework</groupId> 45 <artifactId>spring-context-support</artifactId> 46 </dependency> 47 <dependency> 48 <groupId>dom4j</groupId> 49 <artifactId>dom4j</artifactId> 50 </dependency> 51 <dependency> 52 <groupId>com.belerweb</groupId> 53 <artifactId>pinyin4j</artifactId> 54 </dependency> 55 <dependency> 56 <groupId>commons-collections</groupId> 57 <artifactId>commons-collections</artifactId> 58 </dependency> 59 <dependency> 60 <groupId>org.apache.ant</groupId> 61 <artifactId>ant</artifactId> 62 </dependency> 63 <dependency> 64 <groupId>javax.servlet</groupId> 65 <artifactId>javax.servlet-api</artifactId> 66 <scope>provided</scope> 67 </dependency> 68 </dependencies> 69 70 <build> 71 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 72 <plugins> 73 <plugin> 74 <artifactId>maven-clean-plugin</artifactId> 75 <version>3.0.0</version> 76 </plugin> 77 <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> 78 <plugin> 79 <artifactId>maven-resources-plugin</artifactId> 80 <version>3.0.2</version> 81 </plugin> 82 <plugin> 83 <artifactId>maven-compiler-plugin</artifactId> 84 <version>3.7.0</version> 85 </plugin> 86 <plugin> 87 <artifactId>maven-surefire-plugin</artifactId> 88 <version>2.20.1</version> 89 </plugin> 90 <plugin> 91 <artifactId>maven-jar-plugin</artifactId> 92 <version>3.0.2</version> 93 </plugin> 94 <plugin> 95 <artifactId>maven-install-plugin</artifactId> 96 <version>2.5.2</version> 97 </plugin> 98 <plugin> 99 <artifactId>maven-deploy-plugin</artifactId> 100 <version>2.8.2</version> 101 </plugin> 102 </plugins> 103 </pluginManagement> 104 </build> 105 </project>
二、建立系統管理模塊
前幾步方法同上 ,



點擊后IDEA會生成archetype,但是速度非常慢,如下圖所示

解決方法如下:
打開setting,在VM Options內輸入 -DarchetypeCatalog=internal,重啟idea即可

新模塊完成后,在父模塊pom.xm中會自動添加模塊引用

由於系統管理模塊依賴公共模塊,所以要在本模塊上增加對公共模塊的引用
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <parent> 6 <artifactId>xframe</artifactId> 7 <groupId>xie.frame</groupId> 8 <version>1.0-SNAPSHOT</version> 9 </parent> 10 <modelVersion>4.0.0</modelVersion> 11 12 <artifactId>xframe-system</artifactId> 13 14 <name>xframe-system</name> 15 <packaging>jar</packaging> 16 <properties> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <maven.compiler.source>1.8</maven.compiler.source> 19 <maven.compiler.target>1.8</maven.compiler.target> 20 </properties> 21 22 <dependencies> 23 <dependency> 24 <groupId>junit</groupId> 25 <artifactId>junit</artifactId> 26 </dependency> 27 <dependency> 28 <groupId>xie.frame</groupId> 29 <artifactId>xframe-common</artifactId> 30 <version>${project.version}</version> 31 </dependency> 32 </dependencies> 33 34 </project>
然后添加系統管理模塊的引用包,添加完畢后如下
