第一步 下载并配置
1.官网下载一个maven的压缩包,下载地址:http://maven.apache.org/download.cgi,下载后解压到任意目录
2.配置maven的环境变量
打开一个终端输入vi ~/.bash_profile
按 i 键进入编辑模式
写入以下命令:
export MAVEN_HOME=/usr/local/apache-maven-3.3.9
export PATH=$PATH:$MAVEN_HOMEE/bin
点击esc键退出编辑模式
输入:wq保存退出
输入source ~/.bash_profile使命令立即生效
配置完成后,在终端输入mvn -v来验证是否配置成功
如果可以看到maven版本等信息,说明配置成功。
3.在eclipse中配置maven环境
1.打开eclipse,进入步骤:Eclipse->Preferences->Maven->Installations->add,在输入框Installation home点击右边Directory选择刚刚解压的maven目录,然后就会有maven3.3.9这个版本了,勾选然后点击apply
2.为了提高.jar的下载速度,修改setting设置:Eclipse->Preferences->Maven->Installations->User Settings->User Settings->Browse,setting文件在Maven安装目录/conf/settings.xml,找到该文件并选中即可
3.修改setting代码,镜像配置为国内阿里的:
<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>
-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>uk</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://uk.maven.org/maven2/</url>
</mirror>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://maven.oschina.net/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>nexus</id>
<name>internal nexus repository</name>
<!-- <url>http://192.168.1.100:8081/nexus/content/groups/public/</url>-->
<url>http://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
第二步 在eclipse中安装maven插件
help里面install new software,在work with 中输入“m2e – http://download.eclipse.org/technology/m2e/releases”,选中要安装的插件根据安装提示安装即可,如果报错,点击add,填入m2e和http://download.eclipse.org/technology/m2e/releases,然后选择要安装的maven插件。