1. 程式人生 > >Mac上mvn命令出現The JAVA_HOME environment variable is not defined correctly.

Mac上mvn命令出現The JAVA_HOME environment variable is not defined correctly.

前言

在mac電腦上使用mvn命令一直報:

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

明明你妹配置錯,但是還是報錯,原因博主也不知道

解決方式

定位當前使用者目錄(一般這檔案就在這個位置):open -e .bash_profile
新增maven配置

M2_HOME=/Users/xy/Downloads/apache-maven-3.5.4
PATH=P

ATH:PATH:M2_HOME/bin
export M2_HOME
export PATH
export JAVA_HOME=$(/usr/libexec/java_home)

export JAVA_HOME=$(/usr/libexec/java_home)這句話的路徑很奇怪,但是必須這麼寫才不會出錯。
然後執行source .bash_profile
OK,mvn命令就可以繼續使用了。

另外說一下Idea左側maven外掛無法使用的問題

命令一直報找不到類

解決方式:
在這裡插入圖片描述
VM Options加入:-Dmaven.multiModuleProjectDirectory=$M2_HOME