Mac上JDK的路径是什么? [英] What is path of JDK on Mac ?

查看:283
本文介绍了Mac上JDK的路径是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

位置已从Java 6(由Apple提供)更改为Java 7及更高版本(由Oracle提供).找出此问题的最佳 generic 方法是运行

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

/usr/libexec/java_home

这是一种本机支持的方法,可以找到默认Java安装的路径以及所有现有的替代安装路径.

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_home -h),将会看到可以使用此命令在OS X(java_home --exec ...)上可靠地启动Java程序,并能够显式指定所需的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解析到的Java安装,如下所示:

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

  1. 运行

  1. run

which java

  • 如果您得到类似/usr/bin/java之类的东西,它是指向实际位置的符号链接,请运行

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

    ls -l `which java`
    

    在我的系统上,此输出

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

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

    and therefrom you can read the Java home directory;

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

    if usr/bin/java points to another symbolic link, recursively apply the same approach with

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


  • 一个重要的变化是,如果您先安装Apple的Java,然后再安装Oracle的,则将获得设置.在这种情况下,上面的步骤2将为您提供


    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

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

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

    and that particular java binary is a stub which will resolve the actual java command to call by consulting the JAVA_HOME environment 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.

    这篇关于Mac上JDK的路径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆