Maven GAV

本文详细介绍了Maven坐标(GAV)的概念,包括groupId、artifactId和version的具体含义,并展示了如何使用这些坐标在pom.xml文件中指定依赖。此外,还推荐了一个实用的在线资源用于查找所需的jar包。

先解释一个名词:GAV,也就是下面英文字母的首写,也叫做Maven坐标,是用来唯一标识jar包的。

G:groupId 一般来代表项目名称,如:com.deyang.share

A:artifactId 一般来代表模块名称,如:share-common

V:version 模块版本,如:0.0.1-snapshot

通过这三个标识就可以唯一地确定jar包在maven仓库中的唯一地址了,然后就可以找到对应的jar包。

刚开始学习Maven的时候,苦于不知道去找对应的jar包,后来偶然间知道了一个网站:http://mvnrepository.com/,可以在顶部的搜索框中搜索jar包,然后找到需要的版本,然后可以找到相应的GAV,复制后粘贴到pom.xml中就可以了,maven会去自动下载相应的及其依赖的jar包。

类似如下的结构:

			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>jstl</artifactId>
				<version>1.1.2</version>
			</dependency>


### 查找 Java Maven GAV 坐标的示例 Maven 使用 `groupId`、`artifactId` 和 `version` 来唯一标识项目中的依赖项或模块。这些被称为 GAV 坐标(Group ID, Artifact ID, Version)。以下是几个常见的 GAV 坐标示例: #### 示例 1: Spring Core 的 GAV 坐标 ```xml <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.3.10</version> </dependency> ``` #### 示例 2: JUnit 测试框架的 GAV 坐标 ```xml <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> </dependency> ``` #### 示例 3: Log4j 日志库的 GAV 坐标 ```xml <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.14.1</version> </dependency> ``` 通过上述示例可以看出,GAV 坐标由三部分组成: - **GroupId**: 表示所属组织或公司名称[^1]。 - **ArtifactId**: 表示具体的构件名或者模块名[^2]。 - **Version**: 定义使用的具体版本号。 如果需要手动配置 Maven 工程并指定 GAV 坐标,则可以在项目的 `pom.xml` 文件中定义相关内容。例如,在一个简单的 Maven 项目中可以这样设置父 POM 或者子模块的信息: ```xml <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.0</modelVersion> <!-- 父级工程 --> <parent> <groupId>com.example.parent</groupId> <artifactId>example-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <!-- 当前模块 --> <groupId>com.example.module</groupId> <artifactId>module-example</artifactId> <version>1.0-SNAPSHOT</version> </project> ``` 对于加密签名工具如 GPG 的配置文件路径以及密码选项也可以按照实际需求调整参数[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值