简体   繁体   English

在Mac OS上正确设置$ JAVA_HOME

[英]Setting $JAVA_HOME correctly on Mac OS

I am trying to get maven working on mac but it complains about not being able to locate $JAVA_HOME, so I set up the env variable in the following way 我正在尝试使Maven在Mac上运行,但是它抱怨无法找到$ JAVA_HOME,因此我以以下方式设置了env变量

e xport JAVA_HOME = $(/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home) e xport JAVA_HOME = $(/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home)

I get maven working with this, but evey time I start a shell I get the following error 我正在使用Maven进行操作,但是在启动外壳时却遇到以下错误

-bash: /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home: No such file or directory

Any thoughts? 有什么想法吗?

Can you try the following export JAVA_HOME= /usr/libexec/java_home -v 1.8.0_73` ? 您可以尝试以下export JAVA_HOME= / usr / libexec / java_home -v 1.8.0_73`吗? Also see this What should I set JAVA_HOME to on OSX 另请参阅在OSX上我应该将JAVA_HOME设置为什么?

ps - Adjust the commands for the java versions available on your machine ps-调整计算机上可用的Java版本的命令

In your question, the command shows spaces around the '=' sign in the assignment, which will mess it up. 在您的问题中,该命令在分配中的'='符号周围显示空格,这会使它混乱。

The assignment should look like this: 分配应如下所示:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

You definitely shouldn't have the $(...) around it - that tries to execute the text inside the parentheses, which is why you get that "No such file or directory" error. 您绝对不应该使用$(...) -试图在括号内执行文本,这就是为什么会出现“无此类文件或目录”错误的原因。 Perhaps that came from trying to use examples which show how to execute the OSX java_home command, as shown in the answer to this question: What should I set JAVA_HOME to on OSX 可能是由于尝试使用显示如何执行OSX java_home命令的示例而来的,如以下问题的答案所示: 在OSX上应将JAVA_HOME设置为什么?

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

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