本教程默认已经把jdk配置好,eclipse安装好,接下来安装配置maven。
首先下载maven:https://maven.apache.org/download.cgi

下载好以后解压,在conf目录里找到settings.xml,用记事本打开,有条件的最好用notepad++,保证编码是utf-8,

先设置自己的本地仓库,在settings.xml里加上<localRepository>你自己建立的本地仓库路径</localRepository>

然后设置阿里云镜像,这样下载包的速度会大大提升,在settings.xml中加上
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>

配置环境变量,系统变量里新建一个MAVEN_HOME,路径写下载的MAVEN的路径

path变量里加上一条路径:MAVEN的路径后面加\bin

按住win+R,输入cmd,回车

输入:mvn -v,如果出现版本信息,就是配置成功了。

如果想引入一些基本的包,在cmd命令行里键入:mvn help system,会给本地仓库下载基本的包,

现在打开eclipse,window-->preference-->maven,然后勾选Download repository index updates on starup,把其他的勾取消掉

然后进入maven-->Installations,点击add,选择我们刚才下载的maven,点击finish

勾选刚才add的maven。

进入maven-->User Settings,Global Settings不用填,填了也会被User Settings覆盖,下面的就填自定义的本地仓库路径。

我们去User Settings里的路径看看,可以看到.m2目录里面是找不到settings.xml的,只有一个repository文件夹,我们把conf目录下已经配置好的settings.xml复制过来,保证两边的Settings.xml一样,这边的settings.xml就是用户本人的设置,

再看eclipse,新建一个maven项目,new-->maven project

next,想要项目有基本的骨架就把第一个勾打上,想要空白的maven项目的话就只打第二个

next,选中图中框选的选项,意思是创建web项目


点击finish,maven的javaweb项目就创建好了,下图是项目的目录结构

接下来双击pom.xml,出现六个选项卡

dependencies是add本地仓库里的包的

想引入外网的包,只能通过pom.xml

这样你的第一个maven项目就搭建成功了,想引入什么包,都可以通过pom.xml,通过dependencies来管理自己引入的包,特别方便。
网友评论