Java 如何在 Mac OS X 上安装特定的 JDK?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1577014/
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-12 16:25:27  来源:igfitidea点击:

How to install a specific JDK on Mac OS X?

javamacosinstall

提问by ajeanson

I want to install a specific JDK (the latest for example). For this, I went to the JDK download homepage: http://java.sun.com/javase/downloads/index.jsp. I looked for a Mac version, but I'm a bit surprised to only see downloadable versions for Linux, Windows and Solaris...

我想安装一个特定的 JDK(例如最新的)。为此,我访问了 JDK 下载主页:http: //java.sun.com/javase/downloads/index.jsp。我寻找的是 Mac 版本,但我很惊讶只看​​到适用于 Linux、Windows 和Solaris 的可下载版本......

Here's the message for Mac:

这是 Mac 的消息:

"Apple Computer supplies their own version of Java. Use the Software Update feature (available on the Apple menu) to check that you have the most up-to-date version of Java for your Mac."

“Apple Computer 提供他们自己的 Java 版本。使用软件更新功能(在 Apple 菜单上可用)检查您是否拥有适用于 Mac 的最新版本的 Java。”

OK BUT... when I update Java with Mac I have a JREand not a JDK...

好的但是......当我用Mac更新Java时,我有一个JRE而不是JDK......

I don't understand why a JDK version doesn't exist that is easily downloadable/installable (like a jar to unzip?) for Mac...

我不明白为什么不存在可轻松下载/安装的 JDK 版本(如要解压缩的 jar?),适用于 Mac...

回答by Jesper

As the message says, you have to go to Apple, not Sun, for Java on the Mac. As far as I know, Apple JDK 6 is installed by default on Mac OS X 10.6 (Snow Leopard). Maybe you need to install the developer tools from your Mac OS X installation DVD (the dev tools are an optional install from the OS DVD).

正如消息所说,对于 Mac 上的 Java,您必须去 Apple,而不是 Sun。据我所知,Apple JDK 6 默认安装在 Mac OS X 10.6 (Snow Leopard) 上。也许您需要从 Mac OS X 安装 DVD 安装开发人员工具(开发工具是从 OS DVD 安装的可选安装)。

See: http://developer.apple.com/java/

请参阅:http: //developer.apple.com/java/

NOTEThis answer from 16 Oct 2009 is now outdated; you can get the JDK for Mac OS X from the regular JDK download pageon Oracle's website now.

注意2009 年 10 月 16 日的这个答案现已过时;您现在可以从Oracle 网站上的常规JDK 下载页面获取 Mac OS X 的JDK

回答by Thorbj?rn Ravn Andersen

As a rule you cannot install other versions of Java on a Mac than those provided by Apple through Software Update. If you need Java 6 you must have a 64-bit Intel computer. You should always have Java 5 and 1.4 and perhaps 1.3 installed if you have at least OS X 10.4.

通常,除了 Apple 通过软件更新提供的 Java 版本之外,您不能在 Mac 上安装其他版本的 Java。如果您需要 Java 6,您必须拥有 64 位 Intel 计算机。如果您至少有 OS X 10.4,您应该始终安装 Java 5 和 1.4 以及 1.3。

If you have VERY much elbow grease and is willing to work with beta software you can install the OpenJDK under OS X, but I don't think you want to go there.

如果您有很多手肘油脂并且愿意使用测试版软件,您可以在 OS X 下安装 OpenJDK,但我认为您不想去那里。

回答by ajeanson

The explanation is that JDK is a bit specific and does not contain the library tools.jar. For my development, I need this library and Mac's JDK doesn't provide it:

解释是 JDK 有点特殊,不包含库 tools.jar。对于我的开发,我需要这个库,而 Mac 的 JDK 不提供它:

(Cf. http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html)

(参见http://developer.apple.com/mac/library/documentation/Java/Conceptual/Java14Development/02-JavaDevTools/JavaDevTools.html

tools.jar does not exist. Classes usually located here are instead included in classes.jar. Scripts that rely on the existence of tools.jar need to be rewritten accordingly.

tools.jar 不存在。通常位于此处的类包含在 classes.jar 中。依赖于 tools.jar 存在的脚本需要相应地重写。

It sucks!

糟透了!

回答by Brian M. Carr

As of Mac OS X v10.6(Snow Leopard), you can run Java 6 in 32-bit mode on either 32-bit or 64-bit Intelprocessor equipped Macs.

Mac OS X v10.6(Snow Leopard) 开始,您可以在配备 32 位或 64 位Intel处理器的 Mac上以 32 位模式运行 Java 6 。

If you cannot upgrade to Snow Leopard, Soy Latteis a pre-compiled version of Java 6 for Intel 32-bit.

如果您无法升级到 Snow Leopard,Soy Latte是用于 Intel 32 位的 Java 6 的预编译版本。

回答by Fgblanch

I think this other Stack Overflow question could help:

我认为另一个 Stack Overflow 问题可能会有所帮助:

How to get JDK 1.5 on Mac OS X

如何在 Mac OS X 上获取 JDK 1.5

It basically says that if you need to compile or execute a Java application with an older version of the JDK (for example 1.4 or 1.5), you can do it using the 1.6 because it is backwards compatible. To do it so you will need to add the parameter -source 1.5and/or -target 1.5in the javac options or in your IDE.

它基本上是说,如果您需要使用旧版本的 JDK(例如 1.4 或 1.5)编译或执行 Java 应用程序,您可以使用 1.6 来完成,因为它向后兼容。为此,您需要添加参数-source 1.5和/或-target 1.5在 javac 选项或您的 IDE 中。

回答by Mark Tye

In a comment under @Thilo's answer, @mobibob asked how to set JAVA_HOME in your .bash_profile on a Mac. Answer:

在@Thilo 的回答下的评论中,@mobibob 询问如何在 Mac 上的 .bash_profile 中设置 JAVA_HOME。回答:

export JAVA_HOME=`/usr/libexec/java_home` 

This will dynamically assign to JAVA_HOME the location of the first JDK listed in the "General" tab of "Java Preferences" utility.

这将动态地将“Java 首选项”实用程序的“常规”选项卡中列出的第一个 JDK 的位置分配给 JAVA_HOME。

See Apple Technical Q&A 1170: https://developer.apple.com/library/content/qa/qa1170/_index.html

请参阅 Apple 技术问答 1170:https: //developer.apple.com/library/content/qa/qa1170/_index.html

EDIT:

编辑:

If you prefer parentheses to backticks for command substitution, this also works:

如果您更喜欢括号而不是反引号进行命令替换,这也适用:

export JAVA_HOME=$(/usr/libexec/java_home)

回答by Evan

Compiling with -source 1.5 -target 1.5 (in a JDK 6 environment) will honor only language elements that were in 1.5 and prior. Great. But there were no language changes in 6 anyway. Problem with this approach (on Mac with 1.6) is that using classes that came AFTER 1.5 will still compile because they exist in the rt.jar. So one could run in a 1.5 env and get a class not found exception with no prior warning when compiling. I found this out the hard way with javax.swing.event.RowSorterEvent/Listener. Both entered "Since 1.6" but are not caught with -source 1.5

使用 -source 1.5 -target 1.5(在 JDK 6 环境中)进行编译将仅支持 1.5 及更早版本中的语言元素。伟大的。但无论如何,6 中没有语言变化。这种方法的问题(在 Mac 1.6 上)是使用 1.5 之后的类仍然可以编译,因为它们存在于 rt.jar 中。因此,您可以在 1.5 环境中运行并在编译时获得一个未找到类的异常而没有事先警告。我用 javax.swing.event.RowSorterEvent/Listener 很难找到这一点。两者都输入了“自 1.6”但没有被 -source 1.5 捕获

回答by Roy Calderon

For people using any LION OS X 10.7.X

对于使用任何 LION OS X 10.7.X 的人

They uploaded Java SE 6 version 1.6.0_26 available here

他们上传了 Java SE 6 版本 1.6.0_26 在这里可用

http://support.apple.com/kb/dl1421

http://support.apple.com/kb/dl1421

回答by matt burns

I bought a MacBook Pro yesterday (Mac OS X v10.8(Mountain Lion)) and there is no JDK installed by default...

我昨天买了一台 MacBook Pro(Mac OS X v10.8(Mountain Lion))并且默认没有安装 JDK...

As well as javac, I also found it didn't have packages such as SVNinstalled. It turns out you can get everything from the Apple developer page(you will need to register with your AppleID). SVN is part of the "Command Line Tools" package.

除了javac,我还发现它没有安装SVN之类的包。事实证明,您可以从Apple 开发人员页面获取所有内容(您需要使用 AppleID 进行注册)。SVN 是“命令行工具”包的一部分。

Enter image description here

在此处输入图片说明

This is what happens on a fresh MacBook:

这是在全新 MacBook 上发生的情况:

Enter image description here

在此处输入图片说明

Enter image description here

在此处输入图片说明

Hopefully this will help out other newbies like me ;)

希望这会帮助像我这样的其他新手;)