在 Mac 上理解 Oracle 的 Java [英] Understanding Oracle's Java on Mac

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

问题描述

我已经在 OS X 上使用 Java 很多年了,最近当 Apple 停止默认包含 Java 时,我让 OS 为我安装它(当然是 Apple 的各种).

I've been using Java on OS X for many, many years and recently when Apple stopped including Java by default I let the OS go and install it for me (Apple's variety, of course).

所以现在我使用的是 OS X 10.8,我需要安装 Java 7,所以我刚刚获得了 DMG 形式的 Oracle 更新 15 并运行了安装程序.它更新了我的/usr/bin/java(和相关文件)以指向这里:

So now I'm using OS X 10.8 and I need to install Java 7 so I just got Oracle's Update 15 in DMG form and ran the installer. It updated my /usr/bin/java (and related files) to point here:

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

将其追溯到/System/Library/Frameworks/JavaVM.framework/Versions",一切都指向Current"或CurrentJDK",前者是指向A"(Oracle 的 Java 7,来自我能说的是,不知道为什么它是A"),后者是/System/Library/Java/JavaVirtualMachines/1.6.0.jdk"中指向 Apple 的 Java 6 的链接.

Tracing this back to '/System/Library/Frameworks/JavaVM.framework/Versions' everything either points to 'Current' or 'CurrentJDK', the former being a link to 'A' (which is Oracle's Java 7, from what I can tell, not sure why it is 'A') and the latter being a link to Apple's Java 6 in '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk'.

现在这一切都非常令人困惑,但这甚至还不是我的问题.这里似乎安装了 Java 7:

Now this is all really confusing but this isn't even my question yet. It appears there is a Java 7 installed here:

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

但这里也安装了 Java 7:

But there is also a Java 7 installed here:

/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk

在两者中找到 'java' 并打印出版本会产生相同的版本和构建(java 版本1.7.0_15"),但是,当对文件进行散列时,它们是不同的.

Finding 'java' in both and printing out the version yields the same version and build (java version "1.7.0_15"), however, when hashing the files they are different.

那么这是否意味着 Oracle 在两个不同的地方安装了 Java 7?如果是这样,为什么?我应该使用哪个?以及为什么有些事情仍然指向 Java 6 (CurrentJDK).

So does this mean Oracle installed Java 7 in two different places? If so, why? Which am I supposed to use? And why do some things still point to Java 6 (CurrentJDK).

我查看了 Oracle 的网站,但没有任何内容可以解决.

I've looked on Oracle's website but nothing there clears anything up.

推荐答案

Oracle 的 JVM 仅安装在一个位置.你被误导了!

Oracle's JVM is only installed in one location. You've been misled!

如您所见,/usr/bin 中的 Java 命令是 /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands 中二进制文件的符号链接.该目录中的二进制文件是确定要使用哪个 Java VM* 的存根应用程序,然后在该 VM 版本中执行相应的实际二进制文件.这就是为什么 /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands 中的所有二进制文件在大小上几乎相同的原因,尽管您希望它们能够完全实现不同的功能.

As you've noted, the Java commands in /usr/bin are symlinks to binaries in /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands. The binaries within that directory are stub applications that determine which Java VM to use*, and then exec the corresponding real binary within that VM version. This is why all of the binaries within /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands are almost identical in size, despite the fact that you'd expect them to be implementing quite different functionality.

您可以使用 dtrace 来查看此操作:

You can see this in action by using dtrace:

mrowe@angara:~$ sudo dtrace -n 'syscall::posix_spawn:entry { trace(copyinstr(arg1)); }' -c "/usr/bin/java -version"
dtrace: description 'syscall::posix_spawn:entry ' matched 1 probe
dtrace: pid 44727 has exited
CPU     ID                    FUNCTION:NAME
  8    619                posix_spawn:entry   /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java

java -version 调用时,给定的dtrace 调用打印出posix_spawn 的路径参数.就我而言,存根应用程序在 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk 中找到了 Apple 的 Java 1.6 运行时,并且正在调用该版本的 java 命令.

The given dtrace invocation prints out the path argument to posix_spawn when it is called by java -version. In my case the stub application has found Apple's Java 1.6 runtime in /System/Library/Java/JavaVirtualMachines/1.6.0.jdk and is invoking that version of the java command.

存根二进制文件还有另一个好处:当它们检测到没有安装 Java VM 时,它们会提示用户安装一个.

The stub binaries also have another benefit: when they detect that no Java VM is installed they will prompt the user to install one.

至于 CurrentJDK 符号链接,为了向后兼容,当 Apple 是 OS X 上 JVM 的唯一来源时,我尽我所能告诉它.

As for the CurrentJDK symlink, as best as I can tell this for sake of backwards-compatibility with the past when Apple was the only source of the JVM on OS X.

* 在确定应使用哪个 Java VM 时,会考虑多种因素.JAVA_HOME 如果设置则使用(尝试JAVA_HOME=/tmp java).如果 JAVA_HOME 未设置,则会发现系统上所有虚拟机的列表.JAVA_VERSIONJAVA_ARCH 环境变量(如果设置)用于将虚拟机列表过滤到特定版本和支持的体系结构.然后将结果列表按架构(64 位优于 32 位)和版本(新的更好)进行排序,并返回最佳匹配.

* A combination of factors are considered when determining which Java VM should be used. JAVA_HOME is used if set (try JAVA_HOME=/tmp java). If JAVA_HOME is not set then the list of all virtual machines on the system is discovered. The JAVA_VERSION and JAVA_ARCH environment variables are used, if set, to filter the list of virtual machines to a particular version and supported architecture. The resulting list is then sorted by architecture (preferring 64-bit over 32-bit) and version (newer is better), and the best match is returned.

这篇关于在 Mac 上理解 Oracle 的 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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