Mac电脑下配置maven环境变量
-
打开终端,使用 touch 命令创建 .bash_profile 文件
touch .bash_profile
-
编辑刚刚创建的文件 .bash_profile
vim .bash_profile
输入: M2_HOME=/Users/lizhimin/Documents/maven/apache-maven-3.3.3
(注:根据自己的maven版本以及路径自行修改)
PATH=$M2_HOME/bin:$PATH
export M2_HOME
export PATH-
保存退出,使用
source .bash_profile
(使修改的环境变量生效 / 或者 / 彻底退出终端再进来也可以)
-
验证,终端输入:
mvn -v
-
显示:
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T04:58:10+08:00)
Maven home: /Users/lizhimin/Documents/maven/apache-maven-3.2.3
Java version: 1.7.0_75, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"
-
其他
如果输入 mvn -v 显示如下内容:
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/libexec/java_home/bin/java -
就需要修改我们创建的 .bash_profile 文件
添加:
export JAVA_HOME=$(/usr/libexec/java_home)
然后进行验证,OK .
2015-7-21新增
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
export CLASS_PATH=$JAVA_HOME/lib
PATH=$PATH:$JAVA_HOME/bin
MAVEN_HOME=/Users/lizm/Documents/maven/apache-maven-3.3.3
PATH=$MAVEN_HOME/bin:$PATH
export MAVEN_HOME
export PATH
场景:今天项目开发过程中,需要修改maven的更新地址,连接公司的maven库,然后需改maven包中的setting.xml文件,遇到的问题,之前maven配置好的,一直用的好好的,突然今天终端输入mvn -v 的时候就出现了如上的问题,最终修复。(但愿你也还好)
补充:
修改maven的更新路径(一步,很简单):
打开 apache-maven-3.3.3 > conf > settings.xml
找到标签 修改为:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
<mirror>
<id>awifi-public</id>
<mirrorOf>central</mirrorOf>
<name>awifi public for this Mirror.</name>
<url>http://192.168.10.129:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
(路径写你自己公司的路径就好)
至此,一切OK! ——– @L先生