升级到Java8后,javac仍然显示1.7。
升级到Java8后,javac仍然显示1.7。
我在OSX上从JDK 1.7升级到1.8时遇到问题。升级已完成,但javac仍然返回1.7作为版本号。\n我从Oracle官网下载了JDK 8_u5,并运行了安装程序。\n我还执行了以下步骤:\n> export JAVA_HOME=`/usr/libexec/java_home -v 1.8`(在我的.bashrc文件中执行)\n> echo $JAVA_HOME\n/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home\n> javac -version\njavac 1.7.0_21\n> $JAVA_HOME/bin/javac -version\njavac 1.7.0_21\n> $JAVA_HOME/bin/java -version \njava version \"1.8.0_05\"\nJava(TM) SE Runtime Environment (build 1.8.0_05-b13)\nJava HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)\n我已经删除了Java 1.7(和所有其他JDK版本),然后重新运行了安装程序:\n> ls /Library/Java/JavaVirtualMachines\njdk1.8.0_05.jdk\n仍然没有用,javac报告的版本仍然是1.7.0_21\n> which javac\n/usr/bin/javac\n> ls -ltra /usr/bin/javac \n[snipped] /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac\n在该路径中,Current是一个指向A的符号链接。A/Commands的内容是一系列文件(而不是符号链接)。\n> cd A/Commands\n> ./javac -version\njavac 1.7.0_21\n> ./java -version\njava version \"1.8.0_05\"\nJava(TM) SE Runtime Environment (build 1.8.0_05-b13)\nJava HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)\n编辑\n根据原帖,我使用jenv进行了一些调查,如此答案所建议。\n> jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home \n> jenv global oracle64-1.8.0.05\n> jenv version\noracle64-1.8.0.05(由/Users/martypitt/.jenv/version设置)\n> jenv info java \nJenv将执行:/Users/martypitt/.jenv/versions/oracle64-1.8.0.05/bin/java\n> jenv info javac\nJenv将执行:/Users/martypitt/.jenv/versions/oracle64-1.8.0.05/bin/javac\n> javac -version\njavac 1.7.0_21\n这使我对这是一个在我的路径中潜伏的随机javac并被调用的想法产生了怀疑。\n为了确保,我彻底删除了Java,并重新尝试:\n> cd /Library/Java/JavaVirtualMachines\n> ls \njdk1.7.0_55.jdk \njdk1.8.0_05.jdk\n> sudo rm -rf * \n> ls\n<
After upgrading to Java 8, the issue of javac showing version 1.7 is most likely a bug in the installation process of jre8. This problem occurs when navigating to the jre8 folder, which is the default folder shown by Windows. The java version displayed is 1.8.0, but the javac version remains at 1.7.0_25. However, when navigating to the jdk8 directory, the java version is also 1.8.0, but the javac version is correctly displayed as 1.8.0.
It has been noticed that the jre does not include a javac, so this issue is likely due to incorrect reference settings in the operating system. To resolve this problem, the javac reference in the operating system needs to be manually fixed.
It is suspected that the root cause of this issue is the presence of a javac somewhere in the system. The folder structures in OSX and Windows are different, and OSX scatters its JDK files and pointers to these files throughout the system. Therefore, there is no jdk8 directory in OSX. It is logical that javac is not found within the JRE folder, as it is part of the JDK and not the JRE.
Further investigation has been done on the paths that javac resolves to. Based on the updated information in the question, it is believed that the executed javac is the one within the jdk8 paths. However, it cannot be confirmed whether this is the same version that ships with jdk8. It is strange that this issue occurs even with a vanilla install.
In conclusion, the issue of javac still showing version 1.7 after upgrading to Java 8 is likely caused by a bug in the installation process of jre8. To fix this problem, the javac reference in the operating system needs to be manually corrected.
升级到Java8后,javac仍然显示1.7的原因是:/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK文件出现了问题。解决方法是执行以下命令:
cd /System/Library/Frameworks/JavaVM.framework/Versions/
rm CurrentJDK
ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/ CurrentJDK
此解决方法来源于Mankeh Blog。
另外,也可以参考Super User上的回答,动态切换JDK版本。
更新:我想我找到了问题所在!尝试执行以下命令:
rm -rf ~/Library/Java/Extensions
sudo rm -rf /Library/Java/Extensions
此解决方法来源于Stack Overflow。
感谢Anthony的帮助。不幸的是,/usr/libexec/java_home -v 1.8.0_05 --exec javac -version返回的是javac 1.7.0_21。
非常感谢你的帮助。我真的很喜欢巴西足球队,但很遗憾他们在世界杯上输给了1-7。我是巴西足球队的超级粉丝。
这个解决方法对我有效!删除~/Library/Java/Extensions和/Library/Java/Extensions文件夹。谢谢!
Anthony,你太棒了!删除/Library/Java/Extensions解决了问题!谢谢!
非常非常非常感谢你!我距离卸载我的机器上的jenv只有几分钟,以为它把一切都搞砸了……
我尝试了Mankeh Blog上的解决方法,现在我的java -version命令不工作了。它显示“-bash: java: command not found”错误。我该如何修复它?
你是否链接到了正确的JDK文件夹?(文件夹位置可能根据Java版本而变化)
我的命令是ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/ Current。
此外,是否正确安装了java和javac,并设置了正确的权限?根据你的错误信息,看起来OS X找不到Java的PATH(也许你应该执行echo $PATH命令,找出OS X期望找到Java命令的位置以及实际位置)。
下载并安装Mac OS JDK对我有效:oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html