1.maven下载地址http://maven.apache.org/download.cgi
2.下载后直接解压,存放路径自己决定,我是放在C:\Program Files\Java路径下。
3.配置maven环境:我的电脑->属性->高级系统设置->新建环境变量:MAVEN_HOME , 变量值为刚解压的maven路径,我的是:C:\Program Files\Java\apache-maven-3.5.0。再在Path变量中加上:%MAVEN_HOME%\bin;
注意:配置Maven时,环境变量里面一定要存在JAVA_HOME,即要配置好JDk的环境。
4.windows+r键输入cmd,打开dos命令,输入mvn -v 进行测试
5.Eclipse配置Maven。Window->Preferences->Maven->Installations->Add->Directory 选择刚解压的Maven的路径,点击Finish,然后将它选为默认。
6.更改本地仓库的地址:conf/settings.xml------><localRepository>。在刚解压的maven中的conf/settings.xml中修改。加上 <localRepository>节点,其中路径自己决定。
7.回到Eclispe中,打开Window->Preferences->Maven->User Settings->Global Settings选择到上一步修改的那个settings.xml文件,点击OK即可。
项目报如下错误的解决办法
Description Resource Path Location Type
Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.6.1 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-compiler-plugin:pom:3.6.1 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version pom.xml /crm9 line 1 Maven Configuration Problem
找到Maven本地仓库的目录即C:\Users\Administrator\.m2\repository
删除C:\Users\Administrator\.m2\repository\org\apache\maven\plugins\maven-compiler-plugin下的所有文件
然后右击项目选择【Maven】->【Update Project】
发现重新生成后
C:\Users\Administrator\.m2\repository\org\apache\maven\plugins\maven-compiler-plugin下的文件带.lastUpdated 说明文件没有下载成功。
这时需要配置Maven的setting
打开Maven的安装目录E:\WebGIS\apache-maven-3.6.1-bin\apache-maven-3.6.1\conf\settings.xml
编辑setting.xml文件
<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-central</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/repositories/central/</url> </mirror> <mirror> <id>jboss-public-repository-group</id> <mirrorOf>central</mirrorOf> <name>JBoss Public Repository Group</name> <url>http://repository.jboss.org/nexus/content/groups/public</url> </mirror> </mirrors>
删除C:\Users\Administrator\.m2\repository\org\apache\maven\plugins\maven-compiler-plugin下的所有文件
然后右击项目选择【Maven】->【Update Project】