Mac電腦下配置maven環境變量java
打開終端,使用 touch 命令建立 .bash_profile 文件apache
touch .bash_profile
編輯剛剛建立的文件 .bash_profilevim
輸入:vim .bash_profile
(注:根據本身的maven版本以及路徑自行修改)M2_HOME=/Users/lizhimin/Documents/maven/apache-maven-3.3.3 PATH=$M2_HOME/bin:$PATH export M2_HOME export PATH
保存退出,使用bash
source .bash_profile
(使修改的環境變量生效 / 或者 / 完全退出終端再進來也能夠)maven
驗證,終端輸入:ui
mvn -v
顯示:this
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"
其餘url
若是輸入 mvn -v 顯示以下內容:spa
Error: JAVA_HOME is not defined correctly. We cannot execute /usr/libexec/java_home/bin/java
就須要修改咱們建立的 .bash_profile 文件3d
添加:
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先生