Maven简介
在搭建工程时,需要引入第三方jar包,可能此jar包还依赖与其他的jar包,因为没有第三方类库的依赖关系,会导致classnotfound错误,以此可以使用maven作为项目构建工具。
dependencies元素
此元素包含多个项目依赖需要使用的dependency
dependency元素
dependency元素通过groupId,artifactId以及vesion确定唯一依赖,有人称这三个为坐标。
groupId:组织的唯一标识
artifactId:项目的唯一标识
version:项目的版本
变量定义
<properties> <spring-framework.version>4.1.5.RELEASE</spring-framework.version> </properties> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <scope>${spring-framework.version}</scope> </dependency> |
Maven运作方式
Maven会自动根据dependency中的依赖配置,直接通过互联网在maven中心库下载相关依赖包到.m2目录下,.m2目录是你本地maven库。如果你不知道你所依赖的jar包的dependency怎么写的话。可以到http://mvnrepository.com网站检索。若maven中心库中没有你需要的jar包,你需要通过下面的maven命令打到本地maven库后应用即可,如下
mvn install:install-file -DgroupId=com.oracle “-DartifactId=ojdbc14” “-Dversion=10.2.0.2.0” “-Dpackaging=jar” “-Dfile=D:ojdbc14.jar”