📅  最后修改于: 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. |
打开控制台并执行以下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作为本教程的安装版本。
将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安装。
从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 |
将档案解压缩到要安装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 |
将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 |
现在将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 |
现在打开控制台并执行以下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 |