Java Mac上JDK的路径是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18144660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:43:52  来源:igfitidea点击:

What is path of JDK on Mac ?

macosjava

提问by filipp.kowalski

Im using Mac only at work and I need to set JAVA_HOME to proper path of JDK. I downloaded JDK, installed it and now I can't find it anywhere. I was looking at the internet for the solution, but there is no folder Libraries/Java.

我只在工作时使用 Mac,我需要将 JAVA_HOME 设置为 JDK 的正确路径。我下载了JDK,安装了它,现在我在任何地方都找不到它。我在互联网上寻找解决方案,但没有文件夹 Libraries/Java。

采纳答案by Marko Topolnik

The location has changed from Java 6 (provided by Apple) to Java 7 and onwards (provided by Oracle). The best genericway to find this out is to run

该位置已从 Java 6(由 Apple 提供)更改为 Java 7 及更高版本(由 Oracle 提供)。找出这一点的最佳通用方法是运行

/usr/libexec/java_home

This is the natively supported way to find out both the path to the default Java installation as well as all alternative ones present.

这是本机支持的查找默认 Java 安装路径以及存在的所有替代路径的方法。

If you check out its help text (java_home -h), you'll see that you can use this command to reliably start a Java program on OS X (java_home --exec ...), with the ability to explicitly specify the desired Java version and architecture, or even request the user to install it if missing.

如果您查看其帮助文本 ( java_home -h),您将看到您可以使用此命令在 OS X ( java_home --exec ...)上可靠地启动 Java 程序,并且能够明确指定所需的 Java 版本和架构,甚至可以请求用户如果丢失,请安装它。

A more pedestrian approach, but one which will help you trace specifically which Java installation the command javaresolves into, goes like this:

一种更普通的方法,但可以帮助您具体跟踪命令java解析为哪个 Java 安装的方法,如下所示:

  1. run

    which java
    
  2. if that gives you something like /usr/bin/java, which is a symbolic link to the real location, run

    ls -l `which java`
    

    On my system, this outputs

    /usr/bin/java -> /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java
    

    and therefrom you can read the Java home directory;

  3. if usr/bin/javapoints to another symbolic link, recursively apply the same approach with

    ls -l <whatever the /usr/bin/java symlink points to>
    
  1. which java
    
  2. 如果这给你类似的东西/usr/bin/java,它是到真实位置的符号链接,运行

    ls -l `which java`
    

    在我的系统上,这输出

    /usr/bin/java -> /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java
    

    从那里你可以读取 Java 主目录;

  3. 如果usr/bin/java指向另一个符号链接,则递归地应用相同的方法

    ls -l <whatever the /usr/bin/java symlink points to>
    


An important variation is the setup you get if you start by installing Apple's Java and later install Oracle's. In that case Step 2 above will give you

如果您先安装 Apple 的 Java,然后再安装 Oracle 的 Java,那么您将获得的设置是一个重要的变化。在这种情况下,上面的第 2 步会给你

/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Commands/java

and that particular javabinary is a stub which will resolve the actual javacommand to call by consulting the JAVA_HOMEenvironment variable and, if it's not set or doesn't point to a Java home directory, will fall back to calling java_home. It is important to have this in mind when debugging your setup.

并且该特定java二进制文件是一个存根,它将java通过查询JAVA_HOME环境变量来解析要调用的实际命令,如果未设置或未指向 Java 主目录,则将回退到调用java_home. 在调试设置时记住这一点很重要。

回答by gefei

On my Mac:

在我的 Mac 上:

/System/Library/Frameworks/JavaVM.framework/Home/

btw, did you tried which java?

顺便说一句,你试过which java吗?

回答by kdabir

/System/Library/Frameworks/JavaVM.framework/

/System/Library/Frameworks/JavaVM.framework/

Also see Java 7 path on mountain lion

另请参阅山狮上的 Java 7 路径

回答by kdabir

Have a look and see if the the JDK is at:

看看JDK是否在:

Library/Java/JavaVirtualMachines/ Or /System/Library/Java/JavaVirtualMachines/

库/Java/JavaVirtualMachines/ 或 /System/Library/Java/JavaVirtualMachines/

Check this earlier SO post: JDK on OSX 10.7 Lion

查看较早的 SO 帖子: OSX 10.7 Lion 上的 JDK

回答by Chetan Gole

Which Mac version are you using? try these paths

您使用的是哪个 Mac 版本?试试这些路径

 /System/Library/Frameworks/JavaVM.framework/ OR
 /usr/libexec/java_home

This link might help - How To Set $JAVA_HOME Environment Variable On Mac OS X

此链接可能会有所帮助 -如何在 Mac OS X 上设置 $JAVA_HOME 环境变量