Eclipse安装maven

来源:互联网 发布:化学动画软件 编辑:程序博客网 时间:2024/06/15 14:28

打算弄一个SpringMVC 在eclipse, maven下面:

,在http://maven.apache.org/download.cgi, 下载 apache-maven-3.5.0-bin.zip.

解压到:D:\Program Files\Apache Software Foundation\apache-maven-3.5.0 

配置环境变量:

MAVEN_HOME = D:\Program Files\Apache Software Foundation\apache-maven-3.5.0

M2_HOME = %MAVEN_HOME%

添加Path变量 %MAVEN_HOME%\bin


修改本地仓库,默认位置在${user.home}/.m2/repository

先在MAVEN_HOME下建文件夹repository,然后打开MAVEN_HOME\conf\settings.xml,可以文本编辑器,notepad++不错。

在如下位置添加一行:<localRepository>D:\Program Files\Apache Software Foundation\apache-maven-3.5.0\repository</localRepository>

 <!-- localRepository   The path to the local repository maven will use to store artifacts.   |   | Default: ${user.home}/.m2/repository   <localRepository>usr/local/maven</localRepository>   -->  <localRepository>D:\Program Files\Apache Software Foundation\apache-maven-3.5.0\repository</localRepository>
配置Maven的镜像源,(由于原来的官网下载速度慢,几乎为0)

还是在settings.xml里,在如下位置

    <!-- 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>     -->
添加:

    <mirror>      <id>UK</id>      <name>UK Central</name>      <url>http://uk.maven.org/maven2</url>      <mirrorOf>central</mirrorOf>    </mirror>
或者开源中国的镜像源

        <mirror>            <id>nexus-osc</id>            <mirrorOf>*</mirrorOf>            <name>Nexus osc</name>            <url>http://maven.oschina.net/content/groups/public/</url>        </mirror>
或者阿里巴巴的maven仓库:    

     <mirror>
       <id>nexus-aliyun</id>
       <mirrorOf>*</mirrorOf>
       <name>Nexus aliyun</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
   </mirror> 


用命令检查安装情况:

mvn -v或者echo %MAVEN_HOME%。

最后再eclipse中配置,

进入菜单Window->Preference->Maven->Installations->Add->Directory...选择上面解压目录D:\Program Files\Apache Software Foundation\apache-maven-3.5.0

然后Finish.

再进入Window->Preference->Maven->User Settings,选择User Settings目录,点击Browser, D:\Program Files\Apache Software Foundation\apache-maven-3.5.0\conf\settings.xml

然后Update Settings下面的Reindex目录,应该是

D:\Program Files\Apache Software Foundation\apache-maven-3.5.0\repository

大功告成。

查找相关依赖的网址:

http://search.maven.org/

原创粉丝点击