
Maven工程之间,A 工程继承 B 工程
B 工程:父工程 A 工程:子工程 本质上是 A 工程的 pom.xml 中的配置继承了 B 工程中 pom.xml 的配置。
在父工程中统一管理项目中的依赖信息,具体来说是管理依赖信息的版本。
对一个比较大型的项目进行了模块拆分。 一个 project 下面,创建了很多个 module。 每一个 module 都需要配置自己的依赖信息。
- TIP
-
- [INFO] +- org.springframework:spring-core:jar:4.0.0.RELEASE:compile
- [INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
- [INFO] +- org.springframework:spring-beans:jar:4.0.0.RELEASE:compile
- [INFO] +- org.springframework:spring-context:jar:4.0.0.RELEASE:compile
- [INFO] +- org.springframework:spring-expression:jar:4.0.0.RELEASE:compile
- [INFO] +- org.springframework:spring-aop:jar:4.0.0.RELEASE:compile
- [INFO] | \- aopalliance:aopalliance:jar:1.0:compile
创建的过程和前面创建Maven的Java项目一样,你可以点击这个连接进行查看我之前手动创建的Maven的Java项目,现在我们还是使用手动的方式来创建,后面会说如何使用开发工具idea进行创建。
- <groupId>com.csdn.mavengroupId>
- <artifactId>pro03-maven-parentartifactId>
- <version>1.0-SNAPSHOTversion>
-
- <packaging>pompackaging>
只有打包方式为 pom 的 Maven 工程能够管理其他 Maven 工程。打包方式为 pom 的 Maven 工程中不写业务代码,它是专门管理其他 Maven 工程的工程。
模块工程类似于 IDEA 中的 module,所以需要进入 pro03-maven-parent 工程的根目录,然后运行 mvn archetype:generate 命令来创建模块工程。
模块工程类似于 IDEA 中的 module,所以需要进入 pro03-maven-parent 工程的根目录,然后运行 mvn archetype:generate 命令来创建模块工程。
假设,我们创建三个模块工程:

- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
- <groupId>com.java.mavengroupId>
- <artifactId>pr03-maven-javaartifactId>
- <version>1.0-SNAPSHOTversion>
- <version>1.0-SNAPSHOTversion>
- <packaging>pompackaging>
- <name>pr03-maven-javaname>
- <url>http://maven.apache.orgurl>
- <properties>
- <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
- properties>
- <modules>
- <module>pro04-maven-javamodule>
- <module>pro05-maven-javamodule>
- <module>pro06-maven-javamodule>
- modules>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-coreartifactId>
- <version>4.0.0.RELEASEversion>
- dependency>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-beansartifactId>
- <version>4.0.0.RELEASEversion>
- dependency>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-contextartifactId>
- <version>4.0.0.RELEASEversion>
- dependency>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-expressionartifactId>
- <version>4.0.0.RELEASEversion>
- dependency>
- <dependency>
- <groupId>org.springframeworkgroupId>
- <artifactId>spring-aopartifactId>
- <version>4.0.0.RELEASEversion>
- dependency>
- dependencies>
- dependencyManagement>
- project>
- #### 然后在子工程中运行mvn dependency:list,效果如下:
-
- ```
- TIP
-
- [INFO] org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
- [INFO] org.springframework:spring-core:jar:4.1.4.RELEASE:compile
- [INFO] org.springframework:spring-context:jar:4.1.4.RELEASE:compile
- [INFO] org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
- [INFO] org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
- ```
-
- <properties>
- <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
-
-
- ```xaml
- <csdn.spring.version>4.3.6.RELEASEcsdn.spring.version>
- ```
-
- properties>

















- "1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
-
- <groupId>com.idea.mavengroupId>
- <artifactId>pro01-maven-idea-parentartifactId>
-
- <packaging>pompackaging>
- <version>1.0-SNAPSHOTversion>
- <modules>
- <module>poro2-module-javamodule>
- modules>
-
-
- project>




