mac下安裝配置maven的問題小記

最近開始玩SpringMVC了,就首先得在本身的mac上把maven安裝一下,一波三證仍是出現了幾個問題,仍是記錄一下分享給你們吧。。。java

一、首先去官網下載 maven3.3.9,配置以下:

tar -zxvf apache-maven-3.3.9
sudo mv apache-maven-3.3.9 /usr/local/maven3.3.9
sudo vim ~/.bash_profile
...
M2_HOME="/usr/local/maven3.3.9/bin"
PATH=$PATH:$M2_HOME
export M2_HOME
export PATH
...

從新打開終端以後測試一把 mvn -v,報錯以下:apache

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

查了一下是maven版本和jdk版本不匹配致使的
要麼升級jdk版本,要麼換個低版本的maven試試(這裏我採用這個方案)vim

二、從新下載 maven3.0.5

tar -zxvf apache-maven-3.0.5
sudo mv apache-maven-3.0.5 /usr/local/maven3.0.5
sudo vim ~/.bash_profile
...
M2_HOME="/usr/local/maven3.0.5/bin"
PATH=$PATH:$M2_HOME
export M2_HOME
export PATH
...

從新打開終端以後測試一把 mvn -v,報錯以下:bash

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/classwor
lds/Launcher 
Caused by: java.lang.ClassNotFoundException: org.codehaus.classworlds.Launcher 
        at java.net.URLClassLoader$1.run(Unknown Source) 
        at java.security.AccessController.doPrivileged(Native Method) 
        at java.net.URLClassLoader.findClass(Unknown Source) 
        at java.lang.ClassLoader.loadClass(Unknown Source) 
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
        at java.lang.ClassLoader.loadClass(Unknown Source) 
        at java.lang.ClassLoader.loadClassInternal(Unknown Source) 
Could not find the main class: org.codehaus.classworlds.Launcher.  Program will 
exit.

查了一下,是環境變量配置的問題,修改以下:maven

sudo vim ~/.bash_profile
...
#這裏去掉後面的/bin
M2_HOME="/usr/local/maven3.0.5"
#這裏M2_HOME變量後面加上/bin
PATH=$PATH:${M2_HOME}/bin
export M2_HOME
export PATH
...

最後從新打開終端以後測試一把 mvn -v測試

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 21:51:28+0800)
Maven home: /usr/local/maven3.0.5
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: zh_CN, platform encoding: EUC_CN
OS name: "mac os x", version: "10.11.3", arch: "x86_64", family: "mac"
相關文章
相關標籤/搜索