简体   繁体   中英

The java version in “mvn -version” is different from the version in “java -version” for mac

爪哇版

超凡脱俗

As the screenshot shows, the java version is different, how can I change the java version in maven to 1.8?

Few things to debug

  1. Please check for the cat /usr/local/Cellar/maven/3.6.3_1/bin/mvn (maven uses this if present) - not sure if this has anything with homebrew installed maven. If there are any hardcoded versions, it might cause a difference in behavior.
  2. echo $JAVA_HOME (maven uses this path and complains if not found)
  3. did you set JAVA_HOME explicitly in any of the terminal sessions?

Also, how did you install java and maven? are they both installed using homebrew ?

Additional info

  1. the following alias will help to switch between java versions easily
alias java11="export JAVA_HOME=`/usr/libexec/java_home -v 11`"
alias java8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`"
  1. this can be added to .bashrc or .zshrc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM