Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.html
Maven是一个软件项目管理的综合工具。它基于项目对象模型(POM)的概念,把全部的项目配置信息都定义在pom.xml文件中。经过配置文件,Maven能够管理项目的整个生命周期,包括构建、编译、测试、发布、报告等。java
官网地址apache
从Maven的官网下载与环境匹配的最新版本压缩包。下载以后无需安装,直接解压到指定目录。服务器
下载地址框架
解压缩以后,须要进行环境变量的设置。maven
设置完环境变量以后,在命令行输入命令:mvn -version
验证是否安装成功。分布式
进入Maven目录,打开conf目录下的settings.xml配置文件,添加本地仓库。这样,全部用户均可以共用这个仓库来构建项目。ide
Maven遵循“约定优于配置”的原则进行配置。主要有以下约定:工具
官网推荐的标准目录结构单元测试
IntelliJ IDEA已经整合了Maven到IDE中,能够直接用来建立Maven项目。
Maven的核心是pom.xml,Maven经过这个配置文件完成各类各样的任务。在实际项目中,没必要彻底理解所有配置项目,能够只关注主要的配置信息。关于各配置项目的详细定义,能够参照官网的说明。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- The Basics --> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <packaging>...</packaging> <dependencies>...</dependencies> <parent>...</parent> <dependencyManagement>...</dependencyManagement> <modules>...</modules> <properties>...</properties> <!-- Build Settings --> <build>...</build> <reporting>...</reporting> <!-- More Project Information --> <name>...</name> <description>...</description> <url>...</url> <inceptionYear>...</inceptionYear> <licenses>...</licenses> <organization>...</organization> <developers>...</developers> <contributors>...</contributors> <!-- Environment Settings --> <issueManagement>...</issueManagement> <ciManagement>...</ciManagement> <mailingLists>...</mailingLists> <scm>...</scm> <prerequisites>...</prerequisites> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <distributionManagement>...</distributionManagement> <profiles>...</profiles> </project>
<groupId>
表示组织标识<artifactId>
表示项目名称<version>
表示版本号<packaging>
表示打包的格式<dependencies>
表示依赖关系<parent>
表示继承关系<dependencyManagement>
用于管理依赖信息<modules>
表示聚合关系<properties>
表示值占位符,使用${X}访问,X表明属性<build>
处理声明项目目录结构、管理插件等<reporting>
镜像构建元素<name>
表示项目名称<description>
表示项目描述<url>
表示项目URL<inceptionYear>
表示项目开始年份<licenses>
表示项目licenses<organization>
表示项目组织<developers>
表示项目开发人员<contributors>
表示项目贡献者<issueManagement>
定义所用的缺陷跟踪系统<ciManagement>
定义持续集成构建系统<mailingLists>
定义邮件列表<scm>
定义软件配置系统<prerequisites>
定义前提条件<repositories>
定义仓库<pluginRepositories>
定义插件仓库<distributionManagement>
定义分布式管理系统<profiles>
定义相关设置这些命令能够一块儿使用,但要注意命令的执行顺序:
clean compile package install