Tuesday, June 1, 2010

Install strictly J2SE-1.4 compatible JRE on Mac OS X Snow Leopard

Today I tried to compile a project requiring J2SE-1.4, i.e. with
Bundle-RequiredExecutionEnvironment: J2SE-1.4
specified in its manifest. On OS X 10.6, JRE 1.4 is no longer installed, instead, version 1.4 points to 1.6. Unfortunately, this JRE is not strictly compatible to J2SE-1.4, as I have learned from this error message:
Build path specifies execution environment J2SE-1.4. 
There are no JREs installed in the workspace that are 
strictly compatible with this environment.
Simply making a selection on the 1.6 JVM in the list compatible JREs in Preferences / Java / Installed JREs / Execution Environment / J2SE-1.4 doesn't help (I tried to clean the projects, but 1.6 is not strictly compatible, thus clean doesn't help here). So, I had to install JDK 1.4, which probably is no problem for Windows and Linux users. However, on OS X, you'll have to follow the hints explained at www.macosxhints.com and repeated here for your convenience:
  1. Remove symbolic links in /System/Library/Frameworks/JavaVM.framework/Versions/ pointing from 1.4.* to 1.6 (otherwise, the 1.6 JDK will be overwritten). E.g, in the terminal (with admin rights):
    > cd /System/Library/Frameworks/JavaVM.framework/Versions/
    > sudo rm 1.4*
  2. Download http://support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_4. Yeah, it is still available, but Apple doesn't make live easy for Java developers these days: Do not install this package (as it will overwrite your existing Java versions)! See next step instead
  3. Open downloaded pkg with Pacifist (http://www.charlessoft.com/).
  4. Select JDK 1.4 and 1.4.2, and install it to default location via Pacifist's context menu (see screenshot)
Now, JDK 1.4 is installed on OS X 10.6. We only have to let Eclipse (in my case 3.6RC1) know about it: In Eclipse, select Preferences / Java / Installed JREs / Add Standard VM Enter JRE Home: /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home and JRE Name: JVM 1.4 (or whatever) You will have to close Preferences (OK), and reopen it in order to let the newly added JRE to be added to the list of compatible JREs. In Preferences / Java / Installed JREs / Execution Environments / J2SE-1.4 select JVM 1.4 (now marked with "perfect match") in list of compatible JREs. That's it. Ted Wise provides zipped versions of JVM 1.5 and 1.4, and you may install these versions following his description at http://tedwise.com/2009/09/25/using-java-1-5-and-java-1-4-on-snow-leopard/. In that case, you won't need Pacifist.