maven pom 详解

1. scope作用域
表示依赖的作用域,用来配置依赖jar包可作用的范围
取值含义举例
compile整个项目,参与打包部署 (默认) **common-fileupload
test测试中,不参与打包部署junit
provided写源代码时需要,不参与打包部署servlet-api/jsp-api
runtime运行时需要,参与打包部署mysql-connector
system使用本地系统路径下的jar包,需要与systemPath 一起使用
<dependency>
	<groupId>com.oracle</groupId>
		<artifactId>ojdbc</artifactId>
		<version>14.0</version>
		<scope> system </scope>
		<systemPath>${basedir}/lib/ojdbc-14.jar</systemPath>
</dependency>
2. properties 全局属性
<properties>
	<spring.version>3.14</spring.version>
</properties>
3. 仓库

依赖查找顺序:

本地仓库 -> 本地pom.xml 配置的远程仓库 ->setting.xml 中配置的远程仓库

使用方式:

<!--pom.xml 配置远程仓库-->
<repositories>
	<repository>
		<id>spring_repo</id>
		<url>http://repo.spring.io/milestone</url>
	</repository>
</repositories>

使用场景:

有些最新的jar包,可能在中央仓库上并没有提供,此时可以使用jar包官方提供的仓库
4. plugins 插件
<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-clean-plugin</artifactId>
			<version>2.6.1</version>
		</plugin>
		
<!-- tomcat 插件 -->

		<plugin>
			<groupId>org.apache.tomcat.maven</groupId>
			<artifactId>tomcat7-maven-plugin</artifactId>
			<version>2.2</version>
			<configuration>
				<path>/maven01</path><!--部署时候的访问路径-->
				<port>9999</port><!--访问端口-->
			</configuration>
		</plugin>
	</plugins>
</build>
5. 超级 POM

所有的pom.xml 文件都继承一个父POM称为超级POM

7. Maven 中的关系

1. 继承
一个maven项目可以继承自另一个maven项目,分为子项目,父项目

使用场景:

多个子项目中使用的是相同的依赖或插件,此时可以把相同的配置抽取到一个副项目中,进行统一的管理,保持一致性。

使用步骤:

  1. 父项目打包方式设置为pom

打包方式:
jar: java项目的打包方式,默认值
war: web项目的打包方式
pom: 父项目的打包方式

<packaging>pom</packaging>
  1. 子项目引用父项目,指定父项目的坐标
<parent>
	<groupId>XXX</groupId>
	<artifactId>XXXX</artifactId>
	<version>1.0</version>
	<!--指定父项目的pom.xml文件的相对物理路径-->
	<relativePath>../parent/pom.xml</relativePath>
</parent>

3. 问题: 有时并不是父项目的所有依赖都需要被子项目继承,但是又希望能通过父项目进行统一管理,如版本的控制。

解决: 使用 dependencyManagement

dependencyManagement 表示父项目只进行依赖管理,依赖默认不会被子项目继承

步骤:

  1. 在父项目中配置dependencyManagement
  2. 在子项目中引用父项目的依赖
<dependencyManagement>
	<dependency>
	</dependency>
</dependencyManagement>

2. 聚合

将多个子项目添加到一个父项目中,然后通过父项目进行操作,实现对所有聚合的子项目的操作

<modules>
	<module>../child01</module>
</modules>

3. 依赖

项目C -->项目B–>项目A,依赖的传递

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值