Maven 简明教程
Maven - Environment Setup
Step 1 - Verify Java Installation in Your Machine
首先,打开控制台并根据您正在使用的操作系统执行 java 命令。
First of all, open the console and execute a java command based on the operating system you are working on.
OS |
Task |
Command |
Windows |
Open Command Console |
c:> java -version |
Linux |
Open Command Terminal |
$ java -version |
Mac |
Open Terminal |
machine:< joseph$ java -version |
让我们验证所有操作系统的输出 −
Let’s verify the output for all the operating systems −
OS |
Output |
Windows |
java 11.0.11 2021-04-20 LTS Java™ SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode) |
Linux |
java 11.0.11 2021-04-20 LTS Java™ SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode) |
Mac |
java 11.0.11 2021-04-20 LTS Java™ SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode) |
如果你尚未在你的系统中安装 Java,那么从以下链接下载 Java 软件开发套件 (SDK) http://www.oracle.com 。对于本教程,我们假设已安装 Java 11.0.11 作为版本。
If you do not have Java installed on your system, then download the Java Software Development Kit (SDK) from the following link http://www.oracle.com. We are assuming Java 11.0.11 as the installed version for this tutorial.
Step 2 - Set JAVA Environment
将 JAVA_HOME 环境变量设置为您计算机中安装 Java 的基本目录位置。例如。
Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example.
OS |
Output |
Windows |
Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk11.0.11 |
Linux |
export JAVA_HOME = /usr/local/java-current |
Mac |
export JAVA_HOME = /Library/Java/Home |
在系统路径中追加 Java 编译器位置。
Append Java compiler location to the System Path.
OS |
Output |
Windows |
Append the string C:\Program Files\Java\jdk11.0.11\bin at the end of the system variable, Path. |
Linux |
export PATH = $PATH:$JAVA_HOME/bin/ |
Mac |
not required |
如上所述,使用命令 java -version 验证 Java 安装。
Verify Java installation using the command java -version as explained above.
Step 3 - Download Maven Archive
从 https://maven.apache.org/download.cgi 下载 Maven 3.8.4。
Download Maven 3.8.4 from https://maven.apache.org/download.cgi.
OS |
Archive name |
Windows |
apache-maven-3.8.4-bin.zip |
Linux |
apache-maven-3.8.4-bin.tar.gz |
Mac |
apache-maven-3.8.4-bin.tar.gz |
Step 4 - Extract the Maven Archive
将存档解压到要安装 Maven 3.8.4 的目录。存档将创建一个子目录 apache-maven-3.8.4。
Extract the archive, to the directory you wish to install Maven 3.8.4. The subdirectory apache-maven-3.8.4 will be created from the archive.
OS |
Location (can be different based on your installation) |
Windows |
C:\Program Files\Apache Software Foundation\apache-maven-3.8.4 |
Linux |
/usr/local/apache-maven |
Mac |
/usr/local/apache-maven |
Step 5 - Set Maven Environment Variables
将 M2_HOME、M2、MAVEN_OPTS 添加到环境变量。
Add M2_HOME, M2, MAVEN_OPTS to environment variables.
OS |
Output |
Windows |
Set the environment variables using system properties. M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.8.4 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.8.4 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.8.4 export M2=$M2_HOME/bin export MAVEN_OPTS=-Xms256m -Xmx512m |
Step 6 - Add Maven bin Directory Location to System Path
现在将 M2 变量附加到系统路径。
Now append M2 variable to System Path.
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 |
Step 7 - Verify Maven Installation
现在打开控制台并执行以下 mvn 命令。
Now open console and execute the following mvn command.
OS |
Task |
Command |
Windows |
Open Command Console |
c:> mvn --version |
Linux |
Open Command Terminal |
$ mvn --version |
Mac |
Open Terminal |
machine:~ joseph$ mvn --version |
最后,验证上述命令的输出,其应如下所示 −
Finally, verify the output of the above commands, which should be as follows −
OS |
Output |
Windows |
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: C:\Program Files\Apache Software Foundation\apache-maven-3.8.4 Java version: 11.0.11, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk11.0.11\ Default locale: en_IN, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows" |
Linux |
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Java version: 11.0.11 Java home: /usr/local/java-current/jre |
Mac |
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Java version: 11.0.11 Java home: /Library/Java/Home/jre |