Maven安装(3.8.4版本)

下载maven

官方下载链接:Maven – Download Apache Maven

下载完成后进行解压到自己要安装的目录下

如果下载不成功可以在以下百度云盘获取(3.8.4版本)

链接: 百度网盘 请输入提取码

提取码: t9pc

maven环境配置

新建系统变量:MAVEN_HOME=F:\maven\apache-maven-3.8.6(以自己安装的路径为准)

添加变量值: %MAVEN_HOME%\bin

验证maven环境配置是否成功

输入命令:mvn -version

配置maven仓库

在maven同级目录下建一个maven仓库:maven-repository

在路径F:\maven\apache-maven-3.8.6\conf(自己安装的路径)下找到settings.xml文件

1.找到节点localRepository,在注释外添加自己仓库的地址

配置镜像(采用国内阿里云的镜像下载依赖会快很多

2、在settings.xml配置文件中找到mirrors节点,添加如下配置(注意要添加在<mirrors>和</mirrors>两个标签之间,其它配置同理),放在默认节点的前面。

<!-- 阿里云仓库 -->
<mirror>
	<id>alimaven</id>
	<mirrorOf>central</mirrorOf>
	<name>aliyun maven</name>
	<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>

3、配置JDK,在settings.xml配置文件中找到profiles节点,添加如下配置

<!-- java jdk1.8版本 -->
    <profile>
      <id>jdk-1.8</id>
      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>        
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>

到此,配置完成。win+R运行cmd,输入命令:mvn help:system测试。

常见异常

引入私服或idea升级到2022.2.2版本报错

com.coctrl:starter-swagger:pom:1.0.8.20211211 failed to transfer from http://0.0.0.0/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of maven-default-http-blocker has elapsed or updates are forced. Original error: Could not transfer artifact com.coctrl:starter-swagger:pom:1.0.8.20211211 from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [coctrl-maven (http://lab.coctrl.com:63456/repository/maven-public/, default, releases), aliyun-repos (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)]

Since Maven 3.8.1 http repositories are blocked.

分析

maven在3.8.1 的默认配置文件中增加了一组标签,如果仓库镜像是http 而不是https 就会被拦截禁止访问,而当前公司私服一般是http 而不支持https。

解决方案

1、找到Maven安装目录,编辑 $M2_HOME/conf/settings.xml,注释如下代码

​
<mirror>

<id>maven-default-http-blocker</id>

<mirrorOf>external:http:*</mirrorOf>

<name>Pseudo repository to mirror external repositories initially using HTTP.</name>

<url>http://0.0.0.0/</url>

<blocked>true</blocked>

</mirror>

​

2、降低maven版本。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值