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