----继承
user-parent 的pom.xml文件中是使用<dependencyManagement>标签来管理子类可能用到的依赖包。注意父类项目的打包方式是<packaging>pom</packaging>
<!-- 父类中对依赖包的管理 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<!-- 不会被打包 -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
</dependencyManagement>
子项目中使用parent标签来继承。
<!-- 使用parent标签来配置继承关系 -->
<parent>
<groupId>org.mgang</groupId>
<artifactId>user-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../user-parent/pom.xml</relativePath>
</parent>
子项目中使用到的依赖只需要自定GAV中的GA,也就是groupId和artifactId。这样做的好处是让maven来管理jar包,可以避免包的冲突。
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
</dependencies>
----聚合
在父类的pom.xml中使用modules来聚合子模块。
<!-- 将项目的模块jar,聚合 -->
<modules>
<module>../user-action</module>
<module>../user-core</module>
<module>../user-dao</module>
</modules>
聚合后,只需要运行user-parent,也就是父项目的pom.xml命令mvn clean install,就会将聚合的项目模块也执行响应操作。