相关信息 logs png class 选择 方式 test pri
一、创建父项目
【New】->【Maven Project】
在弹出界面中选择【Create a simple project...】
二、创建子项目
选中刚建的父项目,在弹出菜单中点击【New】->【Other】->【
- Maven Module】
三、优化配置
按上面步骤创建的子项目,在
中有个
- pom.xml
节点,所以,他可以继承父项目的相关信息。
- parent
在子项目的
中,子项目的
- pom.xml
和
- groupId
一般和父项目相同,那么可以把子项目的这两个参数删除,这样会自动继承父项目的取值。
- version
同样,如果其他的一些属性,所有子项目都是一样的,那么可以上移到父项目中设置,子项目中无需重复设置。比如:
可以仅在父项目中设置一次。
- UTF-8</project.build.sourceEncoding>
除了这种情况以外,还有一种情况,就是依赖和插件。依赖和插件的情况是这样,某一个依赖或插件可能会被大部分子项目所使用,但是也可能有些子项目不需要使用,这样使用上述的方式,简简单单地进行继承就不合适。
Manen提供
和
- dependencyManagement
两个标签。使用这两个标签,可以在父项目中统一管理依赖和插件的配置参数,比如版本号。而在子项目中,仅需列出需要使用的依赖和插件的
- pluginManagement
和
- groupId
,其他信息会自动从父项目管理的信息里面获取。
- artifactId
例子,父项目:
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.5</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.5</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
子项目:
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
参考:
http://ju.outofmemory.cn/entry/75620
http://www.cnblogs.com/qiyebao/p/5300539.html
Eclipse创建Maven多模块工程
来源: http://www.bubuko.com/infodetail-2313493.html