mac查看maven版本报错:The JAVA_HOME environment variable is not defined correctly

发布时间:2024年01月17日

终端输入mvn -version报错:
The JAVA_HOME environment variable is not defined correctly,
this environment variable is needed to run this program.
Java环境变量的问题,打开bash_profile查看
open ~/.bash_profile

export JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_361.jdk/Contents/Home
alias jdk8='export JAVA_HOME=$JAVA_8_HOME'
#java17
export JAVA_17_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
alias jdk17='export JAVA_HOME=$JAVA_17_HOME'

JAVA_HOME=$JAVA_8_HOME

export PATH=$PATH:/usr/local/mysql/bin
export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"

# export PATH=${PATH}:/Users/gorwaywong/Library/Python/3.9/bin
export PATH="/Users/gorwaywong/anaconda3/bin:$PATH"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/gorwaywong/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/Users/gorwaywong/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/gorwaywong/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/Users/gorwaywong/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

export PATH="/opt/homebrew/bin:$PATH"

发现Java8和Java17版本的环境变量都有,而且默认是Java8
终端中输入:
jdk17
在这里插入图片描述
查看版本成功.

文章来源:https://blog.csdn.net/weixin_48609829/article/details/135635670
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。