新手如何创建一个Maven项目,详细步骤如下:
1.需要的资源文件
前提:jdk的环境已经配置完成
2.解压文件
新建两个文件夹,分别叫做maven和repository(名字一定不能写错)。将上一步的第一个压缩包解压至maven文件夹中,repository用来作为本地仓库地址。
maven的目录结构应该如下所示:
3.配置Maven环境
3.1 和配置jdk的环境一样,右击电脑属性—>高级系统设置—>环境变量
3.2 将maven文件夹中的bin子文件夹的地址加到path变量中:
3.3 检查一下maven环境配置是否正确(命令:mvn -v):
出现如上图所示的信息表示配置正确
4.配置settings.xml
4.1 打开maven文件夹中的conf子文件夹,找到settings.xml。大概在153行左右,添加阿里云服务。
<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>1</id>
<mirrorOf>*</mirrorOf>
<name>Aliyun Maven Repository</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
大概在53行左右添加本地仓库地址。(也就是新建文件夹repository的地址)
<localRepository>D:/Program Files/repository</localRepository>
完成之后保存!!!
5.使用eclipse关联maven
5.1 首先创建一个maven项目(步骤如下):
输入你的组名和项目名
5.2 将eclipse与maven关联起来
window–>preferences–>maven–>installations(安装位置);
–>Gloable Settings(配置settings.xml)
配置settings.xml文件,不要忘了apply,然后OK。
6.最后可能需要修改一下jdk的编译环境