這里面主要涉及聚合模塊以及父子模塊繼承的問題。掌握好就可以了。
假如你有一個項目名稱為PRJ,依賴下面的三個模塊,分別是common,service,以及web,
目錄結構如下:
PRJ ...聚合模塊,packaging方式為pom,這個很關鍵,然后modules要列出它的子模塊
+common ...JAR
+service ...JAR,依賴common
+web ...WAR,依賴common和service,注意packaging方式為war
那么可以這么寫pom文件
1.PRJ項目的pom.xml:
<groupId>g</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>common</module>
<module>service</module>
<module>web</module>
</modules>
2.common模塊的pom.xml:
<parent>
<groupId>g</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
</parent>
<artifactId>common</artifactId>
3.service模塊的pom.xml:
<parent>
<groupId>g</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
</parent>
<artifactId>service</artifactId>
3.web模塊的pom.xml:
<parent>
<groupId>g</groupId>
<artifactId>a</artifactId>
<version>1.0</version>
</parent>
<artifactId>web</artifactId>
<packaging>war</packaging>
只要你目錄關系正確,那只要模仿上面方式,你針對PRJ或者web進行mvn clean install處理,是可以正常打包的。
至于里面的依賴關系dependencies的寫法,我就省略了,希望能對你有所幫助。