昨天学习 servlet 的时候,发现自己的 jar 包一直下载不下来,试了好几种办法,所谓是万事开头难吧,和大家分享一下,希望能够解决大家遇到的问题.
一、原因分析
💡 jar 包下载失败的原因:它的中央仓库在国外,下载时和你的网速有关,有时就会出现下载不全或者下载失败的情况.
解决方案: 因此,我们需要把下载的网址改为国内源即可,比如阿里云、网易云……我这里设置的是阿里云 Maven 镜像(阿里云Maven中央仓库为阿里云云效提供的公共代理仓库,帮助研发人员提高研发生产效率,使用阿里云Maven中央仓库作为下载源,速度更快更稳定).
二、如何配置
🐻🐻1. 打开 New Projects Setup ——> Settings for New Projects. 不要选择上面的 Settings , 它仅对当前项目有用,你设置了也大概率得新建项目,对以后项目是不起作用的.
![](https://img-blog.csdnimg.cn/img_convert/ff4998b846d9926dcbc650223bccc7af.png#averageHue=#8dada5&clientId=u1eb224fc-176e-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=634&id=u859cbb3b&margin=[object%20Object]&name=image.png&originHeight=713&originWidth=760&originalType=binary&ratio=1&rotation=0&showTitle=false&size=68322&status=done&style=none&taskId=u39786a64-fb31-47d4-925b-ba10b415f7b&title=&width=675.5555555555555)
🐻🐻2. 进到 maven 配置页面中:
(1)选择右侧两个 Override 选项.
(2)检查 Maven home path 一般不用修改,使用默认的即可.
![](https://img-blog.csdnimg.cn/img_convert/2e0df92fc493851ddeaea56723cba0a4.png#averageHue=#3e4247&clientId=u1eb224fc-176e-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=731&id=ua872e3e6&margin=[object%20Object]&name=image.png&originHeight=822&originWidth=1463&originalType=binary&ratio=1&rotation=0&showTitle=false&size=111097&status=done&style=none&taskId=u573562fd-b394-4268-8ff4-b891e65dc53&title=&width=1300.4444444444443)
🐻🐻3. 打开 .m2 目录下,检查是否有 setting.xml 文件.
![](https://img-blog.csdnimg.cn/img_convert/fa54e2e55978740a130bbf5319eec3f5.png#averageHue=#fbfbfa&clientId=u1eb224fc-176e-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=278&id=u693c8a75&margin=[object%20Object]&name=image.png&originHeight=313&originWidth=1092&originalType=binary&ratio=1&rotation=0&showTitle=false&size=24493&status=done&style=none&taskId=ue1f82ab0-dfb9-4c89-b19d-14d0ea6906a&title=&width=970.6666666666666)
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
b. 如果没有此文件,下载下面连接,粘贴到 .m2 目录下即可.
链接: https://www.aliyundrive.com/s/GR4JgG6GvKJ
🐻🐻4. 重新下载 jar 包.
因为此前下载中断或者下载失败,导致本地的 jar 包文件不全,卸载 repository 目录下的所有文件.
![](https://img-blog.csdnimg.cn/img_convert/40c33ae2ddcf85d0aa6e77481dcbd2be.png#averageHue=#fbfaf8&clientId=u1eb224fc-176e-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=526&id=udbe37849&margin=[object%20Object]&name=image.png&originHeight=592&originWidth=1005&originalType=binary&ratio=1&rotation=0&showTitle=false&size=48701&status=done&style=none&taskId=u0ad52bc8-0821-40b3-b627-bc7375ea1a8&title=&width=893.3333333333334)
最后 , 重启 IDEA 并新建项目 ,找到右侧的 Maven 选项,点击刷新即可.如果右侧没有 Maven 的选项,点击项目名,选择 Add Framework Support即可.
![](https://img-blog.csdnimg.cn/img_convert/557ddc195c7b1bbffe62b98482659055.png#averageHue=#3f4447&clientId=u58b6c05c-6c35-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=278&id=u54e3ee6a&margin=[object%20Object]&name=image.png&originHeight=313&originWidth=671&originalType=binary&ratio=1&rotation=0&showTitle=false&size=42383&status=done&style=none&taskId=uabf862c5-08c7-40a5-82f7-cc9b6930db3&title=&width=596.4444444444445)
![](https://img-blog.csdnimg.cn/img_convert/be9670d48039159d8be45ba4d4a95d94.png#averageHue=#434d5a&clientId=u58b6c05c-6c35-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=186&id=u95b603d6&margin=[object%20Object]&name=image.png&originHeight=209&originWidth=484&originalType=binary&ratio=1&rotation=0&showTitle=false&size=38233&status=done&style=none&taskId=ue3ff456e-5f52-472c-855a-ed95e5feb61&title=&width=430.22222222222223)
如果还是下载失败那就是本地⽹速问题或者是上述步骤操作失误,仔细检查,重复步骤2,3,4 ,重复步骤2,3,4 ,重复步骤2,3,4 !!!