简体   繁体   English

java -version告诉我8但jdk是1.7 - OSX 10.9.x

[英]java -version tells me 8 but jdk is 1.7 - OSX 10.9.x

Something I don't understand - I'm on OSX 10.9.5 and when I run java -version at the terminal, I get: 我不明白的东西 - 我在OSX 10.9.5上,当我在终端上运行java -version时,我得到:

java version "1.8.0_40" java版“1.8.0_40”
Java(TM) SE Runtime Environment (build 1.8.0_40-b25) Java(TM)SE运行时环境(版本1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode) Java HotSpot(TM)64位服务器VM(内置25.40-b25,混合模式)

But in my /Library/Java/JavaVirtualMachines/ dir I see 3 JDKs: 但在我的/ Library / Java / JavaVirtualMachines / dir中,我看到3个JDK:

  • jdk1.7.0_71.jdk jdk1.7.0_71.jdk
  • jdk1.7.0_75.jdk jdk1.7.0_75.jdk
  • jdk1.7.0_76.jdk jdk1.7.0_76.jdk

Eclipse uses jdk1.7.0_76.jdk. Eclipse使用jdk1.7.0_76.jdk。 I remember installing Java 7 for some personal dev projects in Eclipse, but I don't recall ever installing Java 8. So why would java -version say I'm running 8? 我记得在Eclipse中为一些个人开发项目安装Java 7,但我不记得曾经安装过Java 8.那么为什么java -version说我运行8? And how can it if no jdk exists for Java 8 in that directory? 如果该目录中的Java 8不存在jdk,怎么办呢?

Confused. 困惑。 TIA. TIA。

The version you are questioning is actually the Java Runtime Environment (JRE) version, not the Java Developer Kit (JDK) version; 您正在质疑的版本实际上是Java Runtime Environment (JRE)版本,而不是Java Developer Kit (JDK)版本; they are two different things. 他们是两个不同的东西。 You are running Java 8 ( JRE ), although you can selectively choose another runtime if there is one available. 您正在运行Java 8( JRE ),但如果有可用的运行时,您可以选择性地选择另一个运行时。

If you want to see all of the versions of Java you might currently have: 如果您想查看当前可能具有的所有Java版本:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
    1.8.0_45,             x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
    1.6.0_65-b14-466.1,   x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-466.1,     i386:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

To see which one is currently running as default: 要查看当前正在运行的默认值:

$ which java ; java -version
/usr/bin/java
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

To see which JDKs are installed: 要查看安装了哪些JDKs

$ ls /Library/Java/JavaVirtualMachines/
jdk1.8.0_45.jdk

The Java Runtime Environment (JRE) Java运行时环境(JRE)

The JRE allows you to run applications written in the Java programming language. JRE允许您运行用Java编程语言编写的应用程序。 Like the JDK, it contains the Java Virtual Machine (JVM), classes comprising the Java platform API, and supporting files. 与JDK一样,它包含Java虚拟机(JVM),包含Java平台API的类和支持文件。 Unlike the JDK, it does not contain development tools such as compilers and debuggers. 与JDK不同,它不包含编译器和调试器等开发工具。

The Java Development Kit (JDK) Java开发工具包(JDK)

The JDK is a development environment for building applications, applets, and components using the Java programming language. JDK是一个使用Java编程语言构建应用程序,applet和组件的开发环境。 The JDK includes tools useful for developing and testing programs written in the Java programming language and running on the Java platform. JDK包括用于开发和测试用Java编程语言编写并在Java平台上运行的程序的工具。

Since Eclipse relies on the tools within the JDK they would most definitely be using one of your installed JDKs , for it couldn't work just using the JRE . 由于Eclipse依赖于JDK的工具,因此它们肯定会使用您安装的JDKs ,因为它无法仅使用JRE

in you .path_profile folder export the JAVA_HOME to your JDK8 folder, java -version is a result of you JVN as it seem to me put you java_home still point to JDK1.7 do the following 在你.path_profile文件夹中导出JAVA_HOME到你的JDK8文件夹,java -version是你JVN的结果,因为在我看来你把java_home还指向JDK1.7做了以下

$ vim .bash_profile 

export JAVA_HOME=YOUR_JDK8_PATH 

$ source .bash_profile

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

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