简体   繁体   English

将JAVA_HOME设置为JDK位置mac osx 10.9.5

[英]setting JAVA_HOME to the JDK location mac osx 10.9.5

I followed this thread to solve my problem, I have the same problem with a different version of JDK and for some reason it didn't work. 我遵循此线程来解决我的问题,但使用不同版本的JDK时遇到相同的问题,并且由于某种原因它无法正常工作。 I still get -bash: JAVA_HOME: command not found when I type JAVA_HOME to my terminal. 我在终端上键入JAVA_HOME时,仍然得到-bash:JAVA_HOME:命令 I have JDK1.8.0.45 located at Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home which I can access with /usr/libexec/java_home 我的JDK1.8.0.45位于Library / Java / JavaVirtualMachines / jdk1.8.0_45.jdk / Contents / Home ,可以使用/ usr / libexec / java_home访问

Using 使用

echo "export JAVA_HOME= /usr/libexec/java_home " >> ~/.profile 回声“导出JAVA_HOME = /usr/libexec/java_home ” >>〜/ .profile

~/.profile 〜/ .profile

I do get " export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home " saved to ~/.profile , and I can check this using /usr/bin/open ~/.profile 我确实将“ export JAVA_HOME = / Library / Java / JavaVirtualMachines / jdk1.8.0_45.jdk / Contents / Home ”保存到〜/ .profile ,我可以使用/ usr / bin / open〜 / .profile进行检查

But I do not understand why JAVA_HOME still doesn't work and I need this to install maven. 但是我不明白为什么JAVA_HOME仍然不起作用,我需要用它来安装Maven。

Thanks! 谢谢!

My ~/.bash_profile has this line in it, and it's been working fine. 我的〜/ .bash_profile中包含这一行,并且运行良好。

export JAVA_HOME=$(/usr/libexec/java_home)

This line basically says "run the program named /usr/libexec/java_home and export its output as a variable named JAVA_HOME." 该行基本上说:“运行名为/ usr / libexec / java_home的程序,并将其输出导出为名为JAVA_HOME的变量。”

I suggest opening your .profile or .bash_profile in a text editor rather than using echo statements to append new lines to it. 我建议在文本编辑器中打开.profile或.bash_profile,而不要使用echo语句在其上添加新行。 That way you can see everything that's in the file and make sure other old lines in the file aren't causing you issues. 这样,您可以查看文件中的所有内容,并确保文件中的其他旧行不会引起问题。

After you make a change to .bash_profile, make sure you open a new terminal window before testing it. 对.bash_profile进行更改后,请确保在测试之前打开新的终端窗口。

You can check the value of any environment variable (including JAVA_HOME) by simply echo'ing its value: 您可以通过简单地回显其值来检查任何环境变量(包括JAVA_HOME)的值:

echo $JAVA_HOME

In my case the output of that echo command is: /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home 在我的情况下,该echo命令的输出为:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home

Probably you misunderstood things. 可能您误会了事情。 JAVA_HOME is not a command, it's an environment variable. JAVA_HOME不是命令,而是环境变量。 You can't call JAVA_HOME in your terminal since - in fact - there is no such command, what your error message says. 您不能在终端中调用JAVA_HOME ,因为-实际上-没有这样的命令,您的错误消息是这样说的。

You can see this variable's value by: 您可以通过以下方式查看此变量的值:

echo $JAVA_HOME

If it is set and points to a proper location then it's fine. 如果已设置并指向正确的位置,那就很好。 Some tools that expect this variable to be set (eg Maven or Java IDEs) will work well. 某些希望设置此变量的工具(例如Maven或Java IDE)可以很好地工作。

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

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