Maven学习(七)

1、继承

①现状:C依赖B,B依赖A

A工程依赖junit :4.0

B程依赖junit :4.0

C工程依赖junit :4.9

由于junit是test范围的依赖,不能传递,所以必然会分散在各个模块工程中。

②需求:统一管理各个模块工程中对应的junit版本

③解决思路:将junit依赖版本统一提取到“父”工程中,在子工程中声明junit依赖

时不指定版本。

④操作步骤

①)创建一个Maven工程作为父工程。注意:打包的方式为pom

②)在子工程中声明对父工程的引用,如下:

<parent>
  <groupId></groupId>
  <artifactId></artifactId>
  <version></version>
 
  <relativePath></relativePath>
  </parent>

③)将子工程坐标中与父工程坐标中重复的内容删除

④)在父工程中统一声明junit依赖

<dependencyManagement>
  <dependencies>
  <dependency>
  <groupId></groupId>
  <artifactId></artifactId>
  <version></version>
  <scope></scope>
  </dependency>
  </dependencies>
  </dependencyManagement>

⑤)在子工程中删除junit依赖的版本号

⑥)注意:配置继承后,执行安装命令时要先安装父工程。

2、聚合

1)作用:一键安装各个模块工程

2)配置方式:(指定各子工程的相对路径)

<modules>
  <module>../hello</module>
  <module>../hellofriends</module>
  </modules>

3)使用方式:在聚合工程的pom.xml上右键点击---run as -- maven installl

3、自动化部署(pom.xml配置

 <!-- 配置当前工程构建过程中的特殊设置 -->
  <build>
  <finalName>testWeb</finalName>
 
  <!-- 配置构建过程中需要使用的插件 -->
  <plugins>
  <plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.2.3</version>
  <
  <configuration>
  <container>
  <containerId>tomcat6x</containerId>
  <home>D:\test\apache-tomcat-6.0.39</home>
  </container>
  </configuration>
 
  </plugin>
  </plugins>
 
  </build>


4、查找依赖信息的网站

http://mvnrepository.com/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值