- google了一下,发现了这篇文章Important Java Directories on Mac OS X(https://developer.apple.com/library/content/qa/qa1170/_index.html),可以使用工具命令“/usr/libexec/java_home”来定位JAVA_HOME,这下爽了:
$ cat ~/.profile
JAVA_HOME=`/usr/libexec/java_home`
export JAVA_HOME
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
另外可以使用-V选项列出所有版本的JAVA_HOME:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
1.7.0_45, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
1.6.0_65-b14-462, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home