Maven安装

maven作为市面上比较通用的项目管理工具,作为JAVA开发,其更是必须知悉的工具。本文只简单的分析下maven的安装

下载安装包

直接去maven的官方网站https://maven.apache.org/download.cgi,选择相应的包进行下载,笔者建议直接下载bin压缩包即可,例如apache-maven-3.6.1-bin.zip

解压

  • Windows用户: 直接用RAR工具或者ZIP工具解压至相应目录即可
  • Linux/Mac用户:使用解压命令即可 tar -zxvf apache-maven-3.3.y.tar.gz

阅读说明文档

在进行相应的环境变量配置前,务必养成一个先阅读官方说明文档的好习惯,以此来避免不必要的错误。

本文截取${maven_home}\README.txt关键的说明部分并加以注释,内含MAVEN介绍、MAVEN环境依赖以及MAVEN安装步骤说明

 
                          Apache Maven

  What is it?
  -----------
  // 介绍Maven是一个依托POM布局概念管理项目的编译、发布以及文档的工具
  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.
  
  // 系统要求,必看,包括JDK版本、内存、硬盘大小、操作系统
  System Requirements
  -------------------

  JDK:
    1.7 or above (this is to execute Maven - it still allows you to build against 1.3
    and prior JDK's).
  Memory:
    No minimum requirement.
  Disk:
    Approximately 10MB is required for the Maven installation itself. In addition to
    that, additional disk space will be used for your local Maven repository. The size
    of your local repository will vary depending on usage but expect at least 500MB.
  Operating System:
    Windows:
      Windows 2000 or above.
    Unix based systems (Linux, Solaris and Mac OS X) and others:
      No minimum requirement.

  // 如何安装Maven
  Installing Maven
  ----------------

  1) Unpack the archive where you would like to store the binaries, eg:

    Unix-based operating systems (Linux, Solaris and Mac OS X)
      tar zxvf apache-maven-3.x.y.tar.gz
    Windows
      unzip apache-maven-3.x.y.zip

  2) A directory called "apache-maven-3.x.y" will be created.
  
  // 如何设置Maven环境
  3) Add the bin directory to your PATH, eg:

    Unix-based operating systems (Linux, Solaris and Mac OS X)
      export PATH=/usr/local/apache-maven-3.x.y/bin:$PATH
    Windows
      set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH%
      
   // JDK环境必须已在Path环境中,方可让Maven跑动起来
  4) Make sure JAVA_HOME is set to the location of your JDK

  // 检查maven是否安装成功
  5) Run "mvn --version" to verify that it is correctly installed.

大致归结如下

  1. 安装前确保JDK环境已配置在v1.7+,且环境变量JAVA_HOME必须定位至jdk的安装目录,而非bin目录。

  2. 配置MAVEN_HOME变量至环境变量中

  3. 采用mvn --version命令来验证maven环境是否安装成功

对上述的结论作下额外的补充

JDK环境以及MAVEN环境配置样例


Linux/Mac系统

1.打开~/.bash_profile环境变量配置文件
vi ~/.bash_profile

2.配置环境变量

#导入JAVA环境
export JAVA_HOME= /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
#导入MAVEN环境
export M2_HOME=/Users/jtj/workroom/mavenroom/apache-maven-3.3.9
export PATH=$PATH:$M2_HOME/bin

3.使配置文件生效source ~/.bash_profile


Windows系统

1.在"计算机"-->"属性"-->"高级系统设置"--->"环境变量"-->新增系统变量JAVA_HOME

JAVA_HOME=D:\apps\java\jdk\1.8\jdk1.8

2.同第一步,新增系统变量MAVEN_HOME

MAVEN_HOME=D:\apps\maven\apache-maven-3.6.1

3.同第一步,选中Path系统变量,新增以下配置

Path=....;%JAVA_HOME%\bin;%MAVEN_HOME%\bin;...

windows_path

4.点击确定保存即可

maven环境测试

使用官方提供的命令mvn --version即可,打印类似如下样例便表示配置OK

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00)
Maven home: /Users/jtj/workroom/mavenroom/apache-maven-3.3.9
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"

小结

MAVEN的安装部署较为简单,所以本文也是简单的罗列之。
但比较重要的是我们得养成一个好习惯,在安装一个新的玩意的时候最好去好好研读下它的说明文档,有事半功倍的效用。

posted @ 2017-03-12 14:51  南柯问天  阅读(344)  评论(0编辑  收藏  举报