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.


Scott K. said...

Please, please, please, stop encouraging people to install unsupported Java VMs on Snow Leopard! This is almost guaranteed to break with the next Java update, and can lead to very subtle crashes in Eclipse. I had to spend two days tracing down some bizarre crashes in Flex Builder on Mac OS X 10.6 that was traced back to someone installing a Java 1.5 from Leopard on Snow Leopard.

Jens v.P. said...

Scott, actually I hate doing these hacks myself. However, what is if a plugin requires 1.4? In my case, I tried to run some JDT tests, and they need 1.4. I'd appreciate a solution without dirty tricks!

Mike said...

Nobody should "require" 1.4. There shouldn't be anything in 1.4 that isn't also included in 1.5 and 1.6!

The plugin needs to be fixed to include a check for version >= 1.4, not just == 1.4.

Jens v.P. said...

Mike, in general I would agree. The plugin "requiring" 1.4 is the JDT test plugin. In that case it makes sense, I quote Andrew Niefer:
"You may want to consider adding an additional 1.4 vm in your preferences
instead of marking the 1.5 vm compatible.
By using the 1.5 class libraries, you could accidentally use 1.5 API in
your J2SE-1.4 bundle and you wouldn't get compile errors." (see Eclipse Forum)

Scott said...

I require 1.4 for older swing apps;
Last Link

If apples going to insist on shipping their own jdk jre
then it should be more backward compatible.

Raphael said...

Tnks very much! You helped me a lot! You are a life saver!

Jakub Holy said...

Thanks a lot! It is incredibely useful because if you're developing an application targeting java 1.4 it is cruical to compile it with 1.4 so that you are sure you don't use API that don't exist there yet.

Lauro Becker said...

This saved my day.

Thank you!

Dale said...

Slightly newer version of Java 1.4 (1.4.2_22) in the package at https://support.apple.com/downloads/DL924/en_US/JavaForMacOSX10.5Update5.dmg. No nice download page, had to punch in the link directly to the DMG myself.

Unknown said...

Hasta que encontré una solución fácil y efectiva! He batallado muchas veces con esto cada vez que necesito regresar a una versión vieja de java en mi MAC.

Muchas gracias!