简体   繁体   English

升级到Java8后,javac仍显示1.7

[英]After upgrading to Java8, javac still shows 1.7

I'm having issues upgrading from JDK 1.7 -> 1.8 on OSX. 我在OSX上从JDK 1.7升级到问题 - > 1.8。 The upgrade has completed, but javac still returns 1.7 as the version. 升级已经完成,但javac仍然返回1.7作为版本。

I've downloaded JDK 8_u5 from Oracle's homepage, and run the installer. 我从Oracle的主页下载了JDK 8_u5 ,然后运行安装程序。

I've also taken the following steps, post-install: 我还在安装后采取了以下步骤:

> export JAVA_HOME=`/usr/libexec/java_home -v 1.8`  (Executed in my .bashrc file)

> echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

> javac -version
javac 1.7.0_21

> $JAVA_HOME/bin/javac -version
javac 1.7.0_21

> $JAVA_HOME/bin/java -version    
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

I've gone through and removed Java 1.7 (and all other JDK versions), and then re-run the installer: 我已经完成并删除了Java 1.7(和所有其他JDK版本),然后重新运行安装程序:

> ls /Library/Java/JavaVirtualMachines
jdk1.8.0_05.jdk

Still no use, javac reports the version as 1.7.0_21 仍然没有用,javac报告版本为1.7.0_21

> which javac
/usr/bin/javac

> ls -ltra /usr/bin/javac 
[snipped] /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac

Within that path, Current is a symlink to A . 在该路径中, CurrentA的符号链接。 The contents of A/Commands are a series of files (not symlinks). A/Commands的内容是一系列文件(不是符号链接)。

> cd A/Commands
> ./javac -version
javac 1.7.0_21

> ./java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

Edit 编辑

Further to the original post, I've done some digging with jenv , as suggested on this answer . 继原来的帖子之后,我已经用jenv做了一些挖掘,就像这个答案所建议的那样。

> jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home                 
> jenv global oracle64-1.8.0.05
> jenv version
oracle64-1.8.0.05 (set by /Users/martypitt/.jenv/version)

> jenv info java 
Jenv will exec : /Users/martypitt/.jenv/versions/oracle64-1.8.0.05/bin/java

> jenv info javac
Jenv will exec : /Users/martypitt/.jenv/versions/oracle64-1.8.0.05/bin/javac

> javac -version
javac 1.7.0_21

This casts dispersions on my thoughts that this was a random javac lurking in my path, which was somehow getting invoked. 这让我想到这是一个随机的javac潜伏在我的路径中,这种方式被某种方式调用了。

To be sure, I've nuked my Java completely, and tried again: 可以肯定的是,我完全修改了我的Java,并再次尝试:

> cd /Library/Java/JavaVirtualMachines
> ls 
jdk1.7.0_55.jdk 
jdk1.8.0_05.jdk
> sudo rm -rf *  
> ls
<<empty>>
> java -version
java version "1.6.0_65"
> javac -version
javac 1.6.0_65
> which javac
/usr/bin/javac

I then re-downloaded a fresh copy the installer and ran it. 然后我重新下载了安装程序新副本并运行它。

> java -version
java version "1.8.0_05"
> javac -version
javac 1.7.0_21

Update 更新

I tried removing all JDK's, XCode and all developer tools, and re-installed fresh. 我尝试删除所有JDK,XCode和所有开发人员工具,然后重新安装。 Same results. 结果相同。

However, I'm still at a loss -- where do I go from here? 但是,我仍然不知所措 - 我从哪里开始? How do I get javac 1.8 to get installed? 如何安装javac 1.8?

If /usr/libexec/java_home -v 1.8.0_05 --exec javac -version returns the correct version, then your problem is with: 如果/usr/libexec/java_home -v 1.8.0_05 --exec javac -version返回正确的版本,那么你的问题是:

/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

With a privileged user execute: 使用特权用户执行:

cd /System/Library/Frameworks/JavaVM.framework/Versions/
rm CurrentJDK
ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/ CurrentJDK

Solution found in Mankeh Blog Mankeh博客中 找到的解决方案


Also check this answer on Super User for dynamically switching JDK versions. 另请在超级用户上查看此答案 ,以动态切换JDK版本。


Update: I guess I've found the culprit! 更新:我想我找到了罪魁祸首!

Try this: 试试这个:

rm -rf ~/Library/Java/Extensions
sudo rm -rf /Library/Java/Extensions

Solution found in: Java 1.7 on OSX 10.9.2 running as 1.5? 找到的解决方案: OSX 10.9.2上的Java 1.7运行为1.5?

For Windows users: 对于Windows用户:

It is possible, that you have to change your PATH variable. 您可能需要更改PATH变量。 Try to set your "%JAVA_HOME%/bin" as the first entry in the PATH. 尝试将“%JAVA_HOME%/ bin”设置为PATH中的第一个条目。

So now it looks like this: 所以现在它看起来像这样:

 PATH    C:\Program Files\anyprogram;C:\Program Files\...;%JAVA_HOME%\bin

And you change it like this: 你改变它是这样的:

 PATH    %JAVA_HOME%\bin;C:\Program Files\anyprogram;C:\Program Files\...

Reason: Any other Program initiates an other Java Version first. 原因:任何其他程序首先启动其他Java版本。

This is (most likely) a bug in the installation process of jre8 . 这(很可能)是jre8安装过程中的一个错误。

I am getting the exact same behaviour when navigating to my jre8 folder, which is the one which Windows (in my case) shows by default: 导航到我的jre8文件夹时,我得到了完全相同的行为,这是Windows(在我的情况下)默认显示的文件夹:

  • java version: 1.8.0, runtime environment 1.8.0-b132, hotspot 64-bit JVM 25.0-b70 java版本:1.8.0,运行时环境1.8.0-b132,热点64位JVM 25.0-b70
  • javac version: 1.7.0_25 javac版本:1.7.0_25

When navigating to the jdk8 directory, it shows the following: 导航到jdk8目录时,它显示以下内容:

  • java version: 1.8.0, runtime environment 1.8.0-b132, hotspot 64-bit JVM 25.0-b70 java版本:1.8.0,运行时环境1.8.0-b132,热点64位JVM 25.0-b70
  • javac version: 1.8.0 javac版本:1.8.0

I did just now notice though that the jre does never ship an javac , so this is an issue in the reference settings in the operating system then I guess. 我刚才注意到,虽然jre永远不会发送javac ,所以这是操作系统参考设置中的一个问题然后我想。

To fix it, you would need to manually fix the javac reference in your OS. 要修复它,您需要在操作系统中手动修复javac引用。

Maybe you can delete the standard .jar file which in your classpath. 也许你可以删除类路径中的标准.jar文件。 When i delete the jar in /Library/Java/Extensions , the problem will be solved. 当我删除/Library/Java/Extensions的jar时,问题将得到解决。 More info : Java compilation error: Mac 更多信息: Java编译错误:Mac

Just adding my own experience here, I installed jdk-8u131-macosx-x64 from Oracle. 只是在这里添加我自己的经验,我从Oracle安装了jdk-8u131-macosx-x64。 Everything worked perfectly. 一切都很完美。 No JAVA_HOME environment variables were present or needed. 没有JAVA_HOME环境变量存在或需要。

mehboob$ javac -version
javac 1.8.0_131

mehboob$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

The /System/Library showed this: / System / Library显示了这个:

mehboob$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.5.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Oct 17  2013 1.6.0 -> CurrentJDK
drwxr-xr-x  8 root  wheel  272 Sep  9  2014 A
lrwxr-xr-x  1 root  wheel    1 Oct 17  2013 Current -> A
lrwxr-xr-x  1 root  wheel   59 Oct 17  2013 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

While the /Library/Java had this: 虽然/ Library / Java有这个:

mehboob$ ls -l /Library/Java/
total 8
drwxrwxr-x  2 root  admin   68 Oct 17  2013 Extensions
lrwxr-xr-x  1 root  wheel   48 Oct 17  2013 Home -> /System/Library/Frameworks/JavaVM.framework/Home
drwxr-xr-x  3 root  wheel  102 Jun  9 11:43 JavaVirtualMachines

There was nothing in Extensions, while JavaVirtualMachines only had the jdk1.8.0_131.jdk folder. Extensions中没有任何内容,而JavaVirtualMachines只有jdk1.8.0_131.jdk文件夹。

This shows that a default installation of JDK works properly with no extra configuration required. 这表明JDK的默认安装正常,无需额外配置。

Firstly, you need to download and then install the jdk8( http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ) 首先,您需要下载并安装jdk8( http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Secondly, do some check as follows: Does your system have a not-linked-for-shell use java 8 already? 其次,做一些检查如下:你的系统是否已经使用了非连接shell for java 8? Try this in you terminal (yes, the apostrophes are important): 在你的终端尝试这个(是的,撇号很重要):

$ '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java' -version 

if it shows " java version "1.8.0_131" " , and then you can go to next step. 如果它显示“java version”1.8.0_131“”,那么你可以转到下一步。

my screenshot 我的截图

Thirdly, edit the bash_profile: 第三,编辑bash_profile:

$ vi ~/.bash_profile 

and type this: 并输入以下内容:

JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib
export JAVA_HOME
export CLASSPATH 

save it and quit, then 然后保存并退出

source ~/.bash_profile 

After the above steps, and check the java version 完成上述步骤后,检查java版本

$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

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

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