一,安装(首先需要配置好JDK环境)
1,官网下载maven安装包:
http://maven.apache.org/download.cgi,解压。例如解压目录:H:\tools\maven\apache-maven-3.5.2。
2,配置系统环境变量:
(1)新增MAVEN_HONE变量
(2)编辑系统变量 path , 添加变量值: ;%MAVEN_HOME%\bin
3,win+r,运行mvn –version检测是否安装成功:
4,修改setting.xml,配置maven,setting.xml如下:
<?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文件的存放地址 -->
<localRepository>H:\tools\maven\repository</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers></servers>
<!--配置maven镜像为阿里云仓库地址-->
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
</mirror>
</mirrors>
<profiles></profiles>
</settings>
二,配置eclipse
window-preference,
选择maven目录下的setting.xml,点击Update Settings,就可以看到在setting.xml中配置的maven文件的存放地址。
三,创建maven项目,运行第一个hello world程序
1,创建项目
file-new-maven project:
点击finish,eclipse就会帮我们创建好一个项目:
2,配置pom.xml,引入相关的依赖包,例如引入junit和apache.commons-lang包:
然后在maven dependencies目录下可以看到maven下载的jar包:
3,创建第一个小程序:
可以运行成功,代表commons-lang包确实下载成功。
至此,第一个maven小程序完成。