Using JDK 1.5 features on Mac OS X


Using JDK 1.5 features on Mac OS X

Although Apple has not yet released a prerelease of Java 1.5 for Mac OS X you can still experiment with some of the features.

First thing you need to do is download the JSR-014 preview release for adding generics to Java 1.4.2. Unfortunately, Apple still hasn’t responded positively to my request for enhancement regarding the non-standard layout of their JDK, so the scripts included with the preview release won’t work on Mac OS X. However, I’ve gone ahead and fixed them so that everyone doesn’t have to pay the same price.

You still need to setup some of the environment variables. I suggest:

export J2SE14=/Library/Java/Home export JSR14DISTR=[wherever you saved it to]

The only real change to the script is the part where they check to make sure there is an rt.jar. Unfortunately on Mac OS X there is no jre directory and even if there was, the jar they are looking for is classes.jar. Oh well, maybe they are just “thinking different” at the expense of easy interoperability. After you have this installed you’ll be able to use the javac/java scripts to use generics, annotations, the new for loop, autoboxing and possibly some things I missed. The annotation support is only at compile time since the current “adding generics” implementation does not provide the new reflection support that is needed at runtime. I’ve had pretty good luck using it except the errors that you get are sometimes a little obfuscated and the autoboxing support doesn’t seem completely fleshed out.

You can also get it working in IntelliJ using their Setup JSR14 Implementation… on the Tools menu. Although to get annotation code to compile you need to further manually change the libraries to include the gcj-rt.jar in the front of the classpath for the module.

I experimented with adding this support directly into the JDK. You can do that for the runtime dependencies but collect.jar can’t be in the bootclasspath for the compiler so you can’t really make it very transparent. If someone else has figured out a good way to do it, that would be great.