Page tree
Skip to end of metadata
Go to start of metadata

Maven 是一个用于构建 Java(或者其他)程序的命令行工具。Maven 项目提供的程序包已经预编译并且包含了所有需要的文件。

Maven 是不需要在计算机系统中进行安装的,你需要做的就是根据你的环境在 Windows 中设置好环境变量就可以了。

Windows Maven 安装技巧

由于环境的不同,Maven 在安装使用的时候可能会出现一些小问题,这里我们将有可能遇到的问题总结出来供大家在使用 Maven 的时候参考。

其中主要涉及到变量名的选取,路径的设置和安装运行 Maven 需要的一些预先安装软件。

下面的内容将会提醒你在使用 Maven 的时候需要注意的一些地方。


和其他跨平台软件一样,如果在重要的变量名称中有空格的话,Maven 将会产生一些未知的错误。建议在 Maven 安装的时候,Maven 的路径中不要包含有任何的空格。


Maven is written in Java (and primarily used to build Java programs). Thus, the major prerequisite is the Java SDK. You need to install the Java SDK (e.g. from} Oracle's download site, and you should install it to a pathname without spaces, such as c:\j2se1.6.

Once Java is installed, you must ensure that the commands from the Java SDK are in your PATH environment variable. Running, for example,

java -version

must show the right version number.

Maven Unpacked

You need to unpack the Maven distribution. Don't unpack it in the middle of your source code; pick some location (with no spaces in the path!) and unpack it there. Let's assume that the path isc:\mvn3.0.4.

Maven in PATH

You run Maven by invoking a command-line tool: mvn.bat from the bin directory of the Maven. To do this conveniently, c:\mvn3.0.4\bin must be in your PATH, just like the J2SE SDK commands. You can add directories to your PATH in the control panel; the details vary by Windows version.

Firewalls and Anti-virus

Firewall and Anti-virus sometimes prevent Java from running properly, or Windows Firewall (and various other Firewalls) actively prevent Java.exe from reaching out to the Internet to "download stuff" which is a key part of Maven You may need to configure the Firewall or Anti-virus to add exceptions to allow such actions.


Unzip the distribution archive, i.e. to the directory you wish to install Maven 3.1.1. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.1.1 will be created from the archive.

Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-3.1.1.

Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.

In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.

Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.

In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.

In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.

Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.

  • No labels