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

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

问题描述

我已经在OS X上使用Java很多年了,最近苹果公司在默认情况下停止使用Java时我会让操作系统为我安装(当然是苹果公司的产品)。

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的Update 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).

我查看了甲骨文的网站,但没有任何内容可以解决。

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

给定的 dtrace 调用打印出 posix_spawn 的路径参数由 java -version 调用。在我的例子中,存根应用程序在 /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_VERSION JAVA_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天全站免登陆