简体   繁体   English

“mvn -version”中的 java 版本与 mac 的“java -version”中的版本不同

[英]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?如截图所示,java 版本不同,如何将 maven 中的 java 版本更改为 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.请检查cat /usr/local/Cellar/maven/3.6.3_1/bin/mvn (如果存在,maven 使用它) - 不确定这是否与安装了homebrew 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) echo $JAVA_HOME (maven 使用此路径,如果找不到则抱怨)
  3. did you set JAVA_HOME explicitly in any of the terminal sessions?您是否在任何终端会话中明确设置了JAVA_HOME

Also, how did you install java and maven?另外,您是如何安装 java 和 maven 的? are they both installed using homebrew ?它们都是使用homebrew安装的吗?

Additional info附加信息

  1. the following alias will help to switch between java versions easily以下别名将有助于在 java 版本之间轻松切换
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这可以添加到.bashrc.zshrc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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