Maven包配置教程
一、找到自己需要下载的maven版本
maven建议下载和idea自带的maven版本一致的
如何找idea自带的maven版本?看下图,
Maven home directory(Maven主目录)选择默认的Bundled(Maven 3)
,此时下方就会显示版本为Version: 3.3.9
二、下载maven
- 如下图,选择maven-3点击进入
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xWMpaiNX-1674972852045)(http://images-bed.wangqinzw.top/202301291324425.png)]
- 找到对应的版本,点击
binaries
进入,source为源码,用不到
- windows选择apache-maven-3.3.9-bin.zip 点击下载即可
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vr3I89mp-1674972852047)(C:/Users/Administrator/AppData/Roaming/Typora/typora-user-images/1674970014586.png)]
-
下载下来解压后的文件如下图
三、配置maven,并且把maven仓库移动
- maven仓库一般默认在c盘,重装系统,就需要重新下载,比较麻烦。
可以直接把maven仓库,配置在d盘
在d盘新建D:\maven\repo
,如图
-
修改
settings.xml
文件文件路径:
D:\maven\apache-maven-3.3.9\conf
第一步:将maven仓库,改为新建的maven仓库
大概在49行到52行原来是这样的,其中
localRepository
意思是本地存储库
<!-- 原来 --> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <!-- 修改后 --> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository--> <localRepository>D:\maven\repo</localRepository>
第二步:将资源镜像改外阿里云镜像的,节省下载时间
大概在135-159行,其中
mirrors
:镜像
<!-- 原来 --> <!-- mirrors | This is a list of mirrors to be used in downloading artifacts from remote repositories. | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | However, this repository may have problems with heavy traffic at times, so people have mirrored | it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that | repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository. |--> <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> </mirrors> <!-- 修改后 --> <!-- mirrors | This is a list of mirrors to be used in downloading artifacts from remote repositories. | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | However, this repository may have problems with heavy traffic at times, so people have mirrored | it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that | repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository. |--> <mirrors> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> </mirrors>
第三步:将
settings.xml
文件复制一份到maven仓库文件夹下 路径:D:\maven\repo\settings.xml
四、配置环境变量
这里不过多说明,不会配置环境变量自行百度。
五、验证是否配置成功
到此步即完成所有配置!