Maven的使用

新建项目这里就不说了,网上一大堆教程,需要的可以去网上找找。

下面要讲的是使用maven搭建项目不需要配置环境变量

 

新建项目之后记得勾选下面两个,选好settings配置文件和仓库的路径

(如果你的settings配置已经设置关联阿里云的仓库地址可以不勾选仓库)

 

settings配置如下

这里的settings的配置 设置关联了本地的仓库

idea下载jar包:首先去本地的远程仓库下载,如果本地的仓库没有就去阿里云的远程仓库下载,下载好jar包存在你的本地仓库

注意:有时候因为网络的某原因导致下载jar包不完整,导致idea引不进jar包,如果遇到这情况,就去本地仓库把引不进的那个jar包删掉,再进行下载即可。

 

 

<?xml version="1.0" encoding="UTF-8"?>  
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
    
       <!--  配置maven本地仓库的地址为D:\maven\repository -->
     <localRepository>D:\maven\repository</localRepository>
     
    <pluginGroups>  
    </pluginGroups>  
    <proxies>  
    </proxies>  
    <servers>  
    </servers> 
    <!-- 配置maven远程仓库地址 是阿里云的仓库地址 -->
    <mirrors>  
        <mirror>  
            <id>aliyun</id>  
            <name>aliyun Maven</name>  
            <mirrorOf>*</mirrorOf>  
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
        </mirror>  
   
    </mirrors>  
    <profiles>  
    </profiles>  
    <activeProfiles>  
    </activeProfiles>  
</settings>  

 

 

jar包不自动下载看看这个有没有勾选(2020以上版本就没有自动下载,需要带下载图标才行)

 

如果使用以上方法还是没有效果,去掉勾选框settings,把远程仓库地址写在pom文件中;先把依赖加载在本地仓库再进行引用。

 

 

pom文件

<repositories>
        <repository>
            <id>nexus-aliyun</id>
            <name>nexus-aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

 

 

 注意:如果项目引不进依赖,需要到本地仓库把对应的依赖删了重新引入 (可能是下载超市,失败的原因)。

还有的就是下载依赖是要确保别的依赖没报错,否则由于某些原因下载不了其它的依赖。

 

感谢来访!

 

posted @ 2020-04-30 23:07  安详的苦丁茶  阅读(186)  评论(0编辑  收藏  举报