Java 如何在 Mac OS X 上获取 JDK 1.5

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

How to get JDK 1.5 on Mac OS X

macosjava

提问by Eric

I've got to write some code for a legacy application that is still running JDK 1.5. Unfortunately, it looks like OS X doesn't actually have a 1.5 JDK installed; it just links to 1.6:

我必须为仍在运行 JDK 1.5 的遗留应用程序编写一些代码。不幸的是,看起来 OS X 实际上没有安装 1.5 JDK;它只是链接到 1.6:

/System/Library/Frameworks/JavaVM.framework/Versions $ ls -l
lrwxr-xr-x  1 root  wheel    5 Apr 26 11:53 1.3 -> 1.3.1
drwxr-xr-x  3 root  wheel  102 Feb 11 15:33 1.3.1
lrwxr-xr-x  1 root  wheel   10 Apr 26 11:53 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Apr 26 11:53 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Apr 26 11:53 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10 Apr 26 11:53 1.5.0 -> CurrentJDK
lrwxr-xr-x  1 root  wheel    5 Apr 26 11:53 1.6 -> 1.6.0
drwxr-xr-x  7 root  wheel  238 Apr 26 11:53 1.6.0
drwxr-xr-x  8 root  wheel  272 Apr 26 11:53 A
lrwxr-xr-x  1 root  wheel    1 Apr 26 11:53 Current -> A
lrwxr-xr-x  1 root  wheel    3 Apr 26 11:53 CurrentJDK -> 1.6

It sounds like from http://developer.apple.com/java/faq/that Java is part of the OS update...I'm on Mac OS X v10.6.3(Snow Leopard). Is there a way to get an actual 1.5 JDK installed on this OS version?

http://developer.apple.com/java/faq/听起来,Java 是操作系统更新的一部分……我使用的是Mac OS X v10.6.3(Snow Leopard)。有没有办法在此操作系统版本上安装实际的 1.5 JDK?

Or do I need to try and find an old version of OS X before I can do this work?

或者我是否需要尝试找到旧版本的 OS X 才能完成这项工作?

采纳答案by Steven Schlansker

If you're writing code in Eclipse or potentially some other IDE, you should be able to configure it to target 1.5 compliance.

如果您在 Eclipse 或其他一些潜在的 IDE 中编写代码,您应该能够将其配置为面向 1.5 合规性。

If you are using javac directly, you could try the -source 1.5and/or -target 1.5javac options, which may be sufficient for what you're doing? The 1.6 JDK should be able to produce 1.5-compliant code.

如果您直接使用 javac,您可以尝试-source 1.5和/或-target 1.5javac 选项,这可能足以满足您的需求?1.6 JDK 应该能够生成符合 1.5 的代码。

回答by J-16 SDiZ

You need a older version of OS X for that.

为此,您需要旧版本的 OS X。

回答by Michael Aaron Safyan

You don't need a copy of Java 1.5 in order to develop for it; Java 1.6 is backwards-compatible with Java 1.5, so anything that would work on 1.5 will work on 1.6. The -sourceand -targetflags may be of use in order to ensure that everything works on 1.5. That said, this articlewill explain how to get a copy of Java 1.5 on Snow Leopard. Be aware, though, that it could potentially trash/harm your system.

您不需要 Java 1.5 的副本来进行开发;Java 1.6 向后兼容 Java 1.5,因此任何适用于 1.5 的东西也适用于 1.6。该-source-target标志可能是有用的,以确保1.5的一切作品。也就是说,本文将解释如何在 Snow Leopard 上获取 Java 1.5 的副本。但是请注意,它可能会破坏/损害您的系统。

回答by Rafael Cordones

Have a look at http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopardon how to get and install 1.4 and 1.5 JDKs on Snow Leopard. Also bear in mind that whenever you run Software Update and a JDK update is installed, you will need to "fix" the symlinks to the 1.4 and 1.5 JDKs.

查看http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard了解如何在 Snow Leopard 上获取和安装 1.4 和 1.5 JDK。还要记住,每当您运行软件更新并安装了 JDK 更新时,您都需要“修复”指向 1.4 和 1.5 JDK 的符号链接。

UPDATE:as a side note, for those developing with several JDKs on OS X, have a look at this handy little utility to switch JDK from the command line: setjdk.

更新:作为旁注,对于那些在 OS X 上使用多个 JDK 进行开发的人,请查看这个从命令行切换 JDK 的方便的小实用程序:setjdk

回答by corvi42

Although the -source and -target flags can be used, they don't always produce code which works on all older JREs. I've definitely had occasions where trying to back-compile to an older spec produced code which worked fine for some users, but wouldn't run on others. To be really sure that everyone using a 1.5 or 1.4 JRE can run your code, you should probably do your production builds with a 1.5 or 1.4 JDK.

尽管可以使用 -source 和 -target 标志,但它们并不总是生成适用于所有旧 JRE 的代码。我肯定有过尝试回编译到旧规范生成的代码的情况,这些代码对某些用户运行良好,但不能在其他用户上运行。要真正确保使用 1.5 或 1.4 JRE 的每个人都可以运行您的代码,您可能应该使用 1.5 或 1.4 JDK 进行生产构建。

I found these instructions very helpful on getting a "real" 1.5 and 1.4 JDK installed under snow leopard: http://codethought.com/blog/?p=233

我发现这些说明对于在雪豹下安装“真正的”1.5 和 1.4 JDK 非常有帮助:http: //codethought.com/blog/?p= 233

回答by n13

Thanks this works great: http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard

谢谢这很好用:http: //wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard

Strangely, you mustfollow the renaming steps in the instructions, where you mod the symlinks for 1.5 and 1.5.0 to the actual leopard Java 1.5 - if you don't do that and just try to run the java binary, you get a bus error!

奇怪的是,您必须按照说明中的重命名步骤进行操作,将 1.5 和 1.5.0 的符号链接修改为实际的 leopard Java 1.5 - 如果您不这样做而只是尝试运行 java 二进制文件,则会得到一条总线错误!

In any case, thanks to these steps I now have an actual Java 5 JDK to compile and run against in Eclipse, which saves me lotsof trouble. For one thing, I can find and remove references to Java 1.6-only methods instantly. It's great. Before these would only show up in QA, or even worse, when one of the few customers still on Java 5 tried to run our program. Which was. Bad.

无论如何,多亏了这些步骤,我现在有了一个实际的 Java 5 JDK 可以在 Eclipse 中编译和运行,这为我省去了很多麻烦。一方面,我可以立即找到并删除对 Java 1.6-only 方法的引用。这很棒。之前这些只会出现在 QA 中,或者更糟的是,当仍然使用 Java 5 的少数客户之一试图运行我们的程序时。那是。坏的。

This is why "supporting" JDK5 while actually just pointing symlinks to Java 6 is not good enough for development.

这就是为什么“支持”JDK5 而实际上只是将符号链接指向 Java 6 对于开发来说还不够好。

回答by James Tikalsky

There are really two problems here:

这里真的有两个问题:

  1. Installing an old version of Java, andkeeping Software Update from removing it.
  2. Telling applications that require the older version where to find it, while letting everything else benefit from the latest version.
  1. 安装旧版本的 Java防止软件更新将其删除。
  2. 告诉需要旧版本的应用程序在哪里找到它,同时让其他一切受益于最新版本。

I don't have anything to add (yet) to what has already been written about installing an old version of Java, however, according to this post from Mike Swingler, Java Runtime Engineer at Apple:

但是,根据Apple 的 Java 运行时工程师Mike Swingler 的这篇文章,我(还)没有什么可以添加到关于安装旧版本 Java 的内容中:

Nobody can or should should be changing symlinks in /System/Library/ Frameworks/JavaVM.framework except for Apple software updates (and we are loath to do so, because it inevitably breaks someone)
除了 Apple 软件更新之外,没有人可以或应该更改 /System/Library/Frames/JavaVM.framework 中的符号链接(我们不愿意这样做,因为它不可避免地会破坏某人)

In other words, updating the Operating System's links to the old copy of Java is a questionable practice, as it forces every Java application on the system to use the old Java version.

换句话说,更新操作系统到 Java 旧副本的链接是一种有问题的做法,因为它强制系统上的每个 Java 应用程序都使用旧的 Java 版本。

The right way is to set JAVA_HOMEto the correct version of Java on an as-needed basis. You can do this by executing /usr/libexec/java_hometo get the path to a specific version. For example, to get the path to a 1.5 version:

正确的方法是根据需要设置JAVA_HOME为正确的 Java 版本。您可以通过执行/usr/libexec/java_home获取特定版本的路径来执行此操作。例如,要获取 1.5 版本的路径:

/usr/libexec/java_home --version 1.5

/usr/libexec/java_home --version 1.5

回答by oligofren

The absolutely easiest way is to use this script by Brice Dutheil. Save the script, download the dmg from Apple (the script will tell you the URI), and run the script. Voila!

最简单的方法是使用 Brice Dutheil 的这个脚本。保存脚本,从 Apple 下载 dmg(脚本会告诉您 URI),然后运行脚本。瞧!