This post originated from an RSS feed registered with Java Buzz
by Michael Cote.
Original Post: Switching Between J2SE 1.4.2 and J2SE 5.0 on OS X
Feed Title: Cote's Weblog: Coding, Austin, etc.
Feed URL: https://cote.io/feed/
Feed Description: Using Java to get to the ideal state.
As noted in a previous post, we started using J2SE 5.0 (or "1.5" as everyone calls it) at work last week. Upgrading the PowerBook was pretty easy.
The anoying thing is that you have to manually go change around symlinks to start using the 5.0 compiler. To do that, you:
$ cd /System/Library/Frameworks/JavaVM.framework/Versions/
mcote-laptop:/System/Library/Frameworks/JavaVM.framework/Versions cote$ ls -l
total 48
lrwxr-xr-x 1 root wheel 5 Jun 29 13:44 1.3 -> 1.3.1
drwxr-xr-x 8 root wheel 272 May 27 14:41 1.3.1
lrwxr-xr-x 1 root wheel 5 Jun 29 13:44 1.4 -> 1.4.2
drwxr-xr-x 9 root wheel 306 Jul 1 09:17 1.4.2
drwxr-xr-x 8 root wheel 272 Jun 10 13:48 1.5.0
drwxr-xr-x 6 root wheel 204 Jun 29 13:45 A
lrwxr-xr-x 1 root wheel 1 Jun 29 13:44 Current -> A
lrwxr-xr-x 1 root wheel 5 Jul 1 20:17 CurrentJDK -> 1.4.2
-rwxr-xr-x 1 root wheel 50 Jun 29 21:48 to14.sh
-rwxr-xr-x 1 root wheel 50 Jun 29 21:48 to50.sh
$ sudo unlink CurrentJDK
$ sudo ln -s 1.5.0 CurrentJDK
$ ls -l
total 48
lrwxr-xr-x 1 root wheel 5 Jun 29 13:44 1.3 -> 1.3.1
drwxr-xr-x 8 root wheel 272 May 27 14:41 1.3.1
lrwxr-xr-x 1 root wheel 5 Jun 29 13:44 1.4 -> 1.4.2
drwxr-xr-x 9 root wheel 306 Jul 1 09:17 1.4.2
drwxr-xr-x 8 root wheel 272 Jun 10 13:48 1.5.0
drwxr-xr-x 6 root wheel 204 Jun 29 13:45 A
lrwxr-xr-x 1 root wheel 1 Jun 29 13:44 Current -> A
lrwxr-xr-x 1 root wheel 5 Jul 1 20:22 CurrentJDK -> 1.5.0
-rwxr-xr-x 1 root wheel 50 Jun 29 21:48 to14.sh
-rwxr-xr-x 1 root wheel 50 Jun 29 21:48 to50.sh
$
And then you're using J2SE 5.0 for your compiler. Exciting!
There's another setting for which VM to use for applets and JARs. That's in Applications->Utilities->Java->J2SE 5.0->Java Preferences.
Easily Switching Back
I'm finishing up my book, JAAS in Action which is primarly done in 1.4.2. So, during the day, I want 5.0, but at night, I want the old version. I got tired of typing unlink, ln, blah, blah, so I made these little scripts that do it for me. You just have to run this with sudo, and they do the trick: