📜  Maven-环境设置

📅  最后修改于: 2020-11-12 04:50:11             🧑  作者: Mango


Maven是一个基于Java的工具,因此最首要的要求是在计算机上安装JDK。

系统要求

JDK 1.7 or above.
Memory No minimum requirement.
Disk Space No minimum requirement.
Operating System No minimum requirement.

第1步-验证计算机上的Java安装

打开控制台并执行以下Java命令。

OS Task Command
Windows Open Command Console c:\> java -version
Linux Open Command Terminal $ java -version
Mac Open Terminal machine:~ joseph$ java -version

让我们验证所有操作系统的输出-

OS Output
Windows

java version “1.7.0_60”

Java(TM) SE Runtime Environment (build 1.7.0_60-b19)

Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

Linux

java version “1.7.0_60”

Java(TM) SE Runtime Environment (build 1.7.0_60-b19)

Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

Mac

java version “1.7.0_60”

Java(TM) SE Runtime Environment (build 1.7.0_60-b19)

Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

如果未安装Java,请从https://www.oracle.com/technetwork/java/javase/downloads/index.html安装Java软件开发工具包(SDK)。我们假定Java 1.7.0.60作为本教程的安装版本。

第2步-设置JAVA环境

JAVA_HOME环境变量设置为指向您的计算机上安装Java的基本目录位置。例如-

OS Output
Windows Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.7.0_60
Linux export JAVA_HOME=/usr/local/java-current
Mac export JAVA_HOME=/Library/Java/Home

将Java编译器位置附加到系统路径。

OS Output
Windows Append the string “;C:\Program Files\Java\jdk1.7.0.60\bin” to the end of the system variable, Path.
Linux export PATH=$PATH:$JAVA_HOME/bin/
Mac not required

如上所述,使用java -version命令验证Java安装。

第3步-下载Maven存档

https://maven.apache.org/download.cgi下载Maven 2.2.1。

OS Archive name
Windows apache-maven-3.3.1-bin.zip
Linux apache-maven-3.3.1-bin.tar.gz
Mac apache-maven-3.3.1-bin.tar.gz

步骤4-提取Maven存档

将档案解压缩到要安装Maven 3.3.1的目录中。子目录apache-maven-3.3.1将从存档中创建。

OS Location (can be different based on your installation)
Windows C:\Program Files\Apache Software Foundation\apache-maven-3.3.1
Linux /usr/local/apache-maven
Mac /usr/local/apache-maven

步骤5-设置Maven环境变量

将M2_HOME,M2,MAVEN_OPTS添加到环境变量。

OS Output
Windows

Set the environment variables using system properties.

M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.1 M2=%M2_HOME%\bin MAVEN_OPTS=-Xms256m -Xmx512m

Linux

Open command terminal and set environment variables.

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.1 export M2=$M2_HOME/bin

export MAVEN_OPTS=-Xms256m -Xmx512m

Mac

Open command terminal and set environment variables.

export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.1

export M2=$M2_HOME/bin

export MAVEN_OPTS=-Xms256m -Xmx512m

步骤6-将Maven bin目录位置添加到系统路径

现在将M2变量附加到系统路径。

OS Output
Windows Append the string ;%M2% to the end of the system variable, Path.
Linux export PATH=$M2:$PATH
Mac export PATH=$M2:$PATH

步骤7-验证Maven安装

现在打开控制台并执行以下mvn命令。

OS Task Command
Windows Open Command Console c:\> mvn –version
Linux Open Command Terminal $ mvn –version
Mac Open Terminal machine:~ joseph$ mvn –version

最后,验证以上命令的输出,应如下所示:

OS Output
Windows

Apache Maven 3.3.1 (r801777; 2009-08-07 00:46:01+0530)

Java version: 1.7.0_60

Java home: C:\Program Files\Java\jdk1.7.0_60 \jre

Linux

Apache Maven 3.3.1 (r801777; 2009-08-07 00:46:01+0530)

Java version: 1.7.0_60

Java home: C:\Program Files\Java\jdk1.7.0_60 \jre

Mac

Apache Maven 3.3.1 (r801777; 2009-08-07 00:46:01+0530)

Java version: 1.7.0_60

Java home: C:\Program Files\Java\jdk1.7.0_60 \jre