转载

Maven环境配置

下一篇  

Maven 是基于Java 的工具,所以第一要求是JDK有安装在你的机器上。

系统要求

JDK 1.5 or above.
Memory no minimum requirement.
Disk Space no minimum requirement.
Operating System no minimum requirement.

Step 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.6.0_21" 
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
Linux java version "1.6.0_21" 
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)
Mac java version "1.6.0_21" 
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)

如果没有安装Java,安装Java软件开发工具包(SDK)http://www.oracle.com/technetwork/java/javase/downloads/index.htmll。我们假设在本教程中安装的版本Java1.6.0_21。

Step 2: 设置Java环境

设置JAVA_HOME环境变量指向的基目录位置在您的机器上已安装Java。例如:

OS Output
Windows Set the environment variable JAVA_HOME to C:/Program Files/Java/jdk1.6.0_21
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.6.0_21/bin to the end of the system variable, Path.
Linux export PATH=$PATH:$JAVA_HOME/bin/
Mac not required

验证Java安装使用java-version命令解释上述。

Step 3: 下载Maven档案

从http://maven.apache.org/download.htmll 下载Maven2.2.1

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

Step 4: 提取Maven的存档

解压压缩包,希望安装Maven2.2.1的目录。从归档文件中将创建的子目录中的Apache Maven2.2.1。

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

Step 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-2.2.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-2.2.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-2.2.1

export M2=%M2_HOME%/bin

export MAVEN_OPTS=-Xms256m -Xmx512m

Step 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

Step 8: 验证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 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21 
Java home: C:/Program Files/Java/jdk1.6.0_21/jre
Linux Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530)
Java version: 1.6.0_21 
Java home: C:/Program Files/Java/jdk1.6.0_21/jre
Mac Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530) 
Java version: 1.6.0_21 
Java home: C:/Program Files/Java/jdk1.6.0_21/jre

恭喜!现在为您的项目都设置为使用Apache Maven。

下一篇  
正文到此结束
Loading...