OSX中自带的Java版本过低, 目前仅为1.6. 现在很多Java应用要求版本为1.7+, 所以必须要升级java.
本文章基于OSX版本: Yosemite 10.10.2
步骤:
- 到Oracle官网上下载最新的OSX JDK.
- 安装下载好的JDK
- 到 /Library/Java/JavaVirtualMachines/ 目录下查看安装的 JDK. 假设最新安装的 JDK 为 jdk1.8.0_20.jdk.
- 更改 CurrentJDK 的软连接. sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
在OS X中, /usr/bin/java* 系列的命令都只是软连接, 连接到 /System/Library/Frameworks/JavaVM.framework/Versions/Current 目录下的java命令:
$ ll /usr/bin/java*
lrwxr-xr-x 1 root wheel 74B 3 26 09:37 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
lrwxr-xr-x 1 root wheel 75B 3 26 09:37 /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
lrwxr-xr-x 1 root wheel 77B 3 26 09:37 /usr/bin/javadoc -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javadoc
lrwxr-xr-x 1 root wheel 75B 3 26 09:37 /usr/bin/javah -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javah
lrwxr-xr-x 1 root wheel 75B 3 26 09:37 /usr/bin/javap -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javap
lrwxr-xr-x 1 root wheel 76B 3 26 09:37 /usr/bin/javaws -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javaws
而 /System/Library/Frameworks/JavaVM.framework/Versions/Current 是 /System/Library/Frameworks/JavaVM.framework/Versions/A 的软连接:
$ ll /System/Library/Frameworks/JavaVM.framework/Versions/Current
lrwxr-xr-x 1 root wheel 1B 3 26 09:37 /System/Library/Frameworks/JavaVM.framework/Versions/Current -> A
JDK 的安装过程中, 会替换 /System/Library/Frameworks/JavaVM.framework/Versions/A 目录下的文件.
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK 也是一个软连接, 连接到当前的JDK.
$ ll /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
lrwxr-xr-x 1 root wheel 58B 3 27 14:20 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents