相关文章推荐
活泼的双杠  ·  ssm ...·  1 年前    · 
含蓄的松球  ·  Kubernetes 中部署 Maven ...·  1 年前    · 
狂野的投影仪  ·  Oops!!! - 简书·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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:

/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?

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

Have a look at http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard on 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.

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.

  • Installing an old version of Java, and keeping Software Update from removing it.
  • Telling applications that require the older version where to find it, while letting everything else benefit from the latest version.
  • 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:

    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)

    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.

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

    /usr/libexec/java_home --version 1.5

    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 -source and -target flags may be of use in order to ensure that everything works on 1.5. That said, this article will explain how to get a copy of Java 1.5 on Snow Leopard. Be aware, though, that it could potentially trash/harm your system.

    The JRE is backwards compatible. Not so with the JDK; if any classes implement new interfaces in the jdk you are using, then you will get an error saying that you need to implement these new methods. – oligofren Jan 18, 2012 at 16:46 Right, but how often does a method get removed or renamed from one version of the JDK to another? Typically methods only get added. Deprecations usually take several versions of the JDK to get completely removed. – Michael Aaron Safyan Jan 19, 2012 at 7:55 Ehh.. exactly :) I never mentioned removal of methods. If you try to compile source code made for JDK 1.5 with JDK 1.6, and that source code implements interfaces that since have been extended (added methods) in JDK 1.6, then you will need to change the old source code to implement the new methods. Backwards compatibility? – oligofren Jan 19, 2012 at 12:20

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

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

    Just a note that even this is a best guess at compatibility. If any new JDK 1.6 classes or methods are used, you're still screwed. I've been bitten by that so many times since osx yanked 1.5, it's quite infuriating. – David Blevins Nov 12, 2010 at 18:10 -1 It doesn't always work when setting the target compliance to 1.5. I'm having this exact problem, because java.sql.CallableStatement changed radically between 1.5 and 1.6. Some classes in this project I'm trying to build implement that interface according to the 1.5 version, so when I try to build (even with 1.5 compliance) it complains that the classes do not fully implement the interface... because the interface is the 1.6 version despite using 1.5 compliance. – Kenny Wyland Apr 5, 2011 at 16:52 I have the same problem as Kenny: isWrapperFor(java.Lang.Class<?> was added to java.sql.Wrapper in version 1.6 of Java. Setting source/target does not help with this. – oligofren Jan 18, 2012 at 16:44 The answer is incomplete/incorrect (see Kenny's comment). See my answer below for how to download and install JDK 1.5 in 1 min. Solves this. – oligofren Jan 18, 2012 at 17:04 Yes, there are limitations. But if you don't trip over the specific issues, it does save you having multiple JDKs installed. – Steven Schlansker Jan 18, 2012 at 17:52

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

    Strangely, you must follow 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!

    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 lots of 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.

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

    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.

    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

    That is simply incorrect. You can get it from apple: support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_9 Here is a script to install it for you: blog.arkey.fr/2011/08/22/… – oligofren Jan 18, 2012 at 16:59

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.