简体   繁体   English

OS X Yosemite 找不到 Java 8 运行时

[英]OS X Yosemite not finding Java 8 runtime

I installed Java 8 SDK (with update 25 for JRE) from the Oracle Java site using the instructions on this page我使用此页面上的说明从 Oracle Java 站点安装了 Java 8 SDK(带有更新 25 的 JRE)

http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html

and put the following line in my ~/.bash_profile并将以下行放在我的~/.bash_profile

export JAVA_HOME="/usr/libexec/java_home -v 1.8"

but when I try to compile or run a Java program in Bash I get the following message但是当我尝试在 Bash 中编译或运行 Java 程序时,我收到以下消息

No Java runtime present, requesting install.

and this window还有这个窗口

I ran /usr/libexec/java_home to check:我跑/usr/libexec/java_home来检查:

$ /usr/libexec/java_home
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.

But the JRE is in但是 JRE 在

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

and the JRE location in System Preferences is pointing to并且系统偏好设置中的 JRE 位置指向

/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin

I don't know what the problem is here, but usr/bin/javac and /usr/bin/java are not able to find the correct JVM location in /System/Library/Frameworks/JavaVM.framework/Versions/Current .我不知道这里有什么问题,但是usr/bin/javac/usr/bin/java无法在/System/Library/Frameworks/JavaVM.framework/Versions/Current找到正确的JVM位置。

我遇到了同样的问题,我认为你应该安装JDK而不是JRE

You need to add some backticks:您需要添加一些反引号:

export JAVA_HOME="`/usr/libexec/java_home -v 1.8`"

The /usr/libexec/java_home command outputs the right value for JAVA_HOME on its standard output, you need to use backticks to capture that value so you can store it in the variable. /usr/libexec/java_home命令在其标准输出上输出JAVA_HOME的正确值,您需要使用反引号来捕获该值,以便将其存储在变量中。

But the JRE is in /System/Library/Frameworks/JavaVM.framework/Versions/Current但是 JRE 位于 /System/Library/Frameworks/JavaVM.framework/Versions/Current

No, it isn't.不,它不是。 The Oracle JRE installs itself under /Library/Internet Plug-Ins , the Oracle JDK installs under /Library/Java/JavaVirtualMachines . Oracle JRE安装在/Library/Internet Plug-Ins ,Oracle JDK安装在/Library/Java/JavaVirtualMachines The binaries under /usr/bin and /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands are stubs that delegate to whichever JDK your JAVA_HOME variable points to. /usr/bin/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands下的二进制文件是将JAVA_HOME变量指向的任何 JDK 委托给的存根。

Here's how I solved my problem on my mac这是我在 Mac 上解决问题的方法

  1. Check from RStudio if Java_HOME has been setup properly by running Sys.getenv("JAVA_HOME") in the console.通过在控制台中运行Sys.getenv("JAVA_HOME")从 RStudio 检查 Java_HOME 是否已正确设置。 If it returns blank, you need to set it up properly如果返回空白,则需要正确设置

  2. Check whether you have Java SDK installed检查您是否安装了 Java SDK

    • Open terminal and check if you have Java SDK installed打开终端并检查您是否安装了 Java SDK
    • Run the /usr/libexec/java_home -v command.运行/usr/libexec/java_home -v命令。 This will show you the library where you Java SDK is installed.这将向您显示安装了 Java SDK 的库。
  3. If you don't have Java SDK installed yet, result from command above is blank, or the version is not up-to-date, download here and install the latest version.如果你还没有安装Java SDK,上面命令的结果是空白,或者版本不是最新的,请在这里下载并安装最新版本。

  4. Copy the library shown in step 2. On my mac, it shows: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home复制步骤 2 中显示的库。在我的 Mac 上,它显示: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home

  5. Back on your RStudio console, set the JAVA_HOME Sys.setenv(JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home")回到你的 RStudio 控制台,设置 JAVA_HOME Sys.setenv(JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home")

After doing the steps above, h2o.init() ran without hitch.完成上述步骤后, h2o.init()运行顺利。

Please carefully note @Ian Robert's point on JRE vs JDK distinction.请仔细注意@Ian Robert 关于JREJDK区别的观点。 We need JDK to make h2o run.我们需要JDK来运行 h2o。

I've tried several solutions, downloading several sdk but Android Studio didn't recognize them as valid sdks.我尝试了几种解决方案,下载了几个 sdk,但 Android Studio 没有将它们识别为有效的 sdk。

Finally, the workaround that worked for me was:最后,对我有用的解决方法是:

  1. Delete Android Studio.app and Android Studio preferences (~/Library/Preferences/AndroidStuido).删除 Android Studio.app 和 Android Studio 首选项 (~/Library/Preferences/AndroidStuido)。
  2. Rename /usr/libexec/java_home to java_home.bak.将 /usr/libexec/java_home 重命名为 java_home.bak。
  3. Install again Android Stuido.再次安装Android Stuido。
  4. When Android Studio prompts for a valid Java SDK, follow link provided by Android Studio and download that java installation.当 Android Studio 提示输入有效的 Java SDK 时,请按照 Android Studio 提供的链接下载该 Java 安装。
  5. After installation, push detect button on Android Studio, and run.安装完成后,在 Android Studio 上按下检测按钮,然后运行。

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

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