Java 1.6 on OS X


Today I was presented with the following error

java.lang.UnsupportedClassVersionError: Bad version number in .class file

My first instinct was of course that I must be using an older vm on the machine in question (an OS X 10.5.6 server), but no, java 1.6 was installed on this machine:

~$ ls -alF /System/Library/Frameworks/JavaVM.framework/Versions/
total 56
drwxr-xr-x  14 root  wheel  476 25 Sep 10:43 ./
drwxr-xr-x  12 root  wheel  408  1 Nov 18:28 ../
lrwxr-xr-x   1 root  wheel    5 25 Sep 10:43 1.3@ -> 1.3.1
drwxr-xr-x   3 root  wheel  102  2 Nov  2007 1.3.1/
lrwxr-xr-x   1 root  wheel    5 25 Sep 10:43 1.4@ -> 1.4.2
lrwxr-xr-x   1 root  wheel    3 16 Jun  2008 1.4.1@ -> 1.4
drwxr-xr-x   8 root  wheel  272 25 May  2007 1.4.2/
lrwxr-xr-x   1 root  wheel    5 25 Sep 10:43 1.5@ -> 1.5.0
drwxr-xr-x   8 root  wheel  272 25 May  2007 1.5.0/
lrwxr-xr-x   1 root  wheel    5 25 Sep 10:43 1.6@ -> 1.6.0
drwxr-xr-x   8 root  wheel  272 16 Jun  2008 1.6.0/
drwxr-xr-x   8 root  wheel  272 25 Sep 10:43 A/
lrwxr-xr-x   1 root  wheel    1 25 Sep 10:43 Current@ -> A
lrwxr-xr-x   1 root  wheel    3 25 Sep 10:43 CurrentJDK@ -> 1.5

A little further investigation revealed that, even though 1.6 is installed, 1.5 is still firmly the default:

~$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Server VM (build 1.5.0_16-133, mixed mode)

Thankfully, this can be changed by aliasing java to the 1.6 version:

~$ alias java=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java
~$ java -version
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06-153)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-57, mixed mode)

Do this in your .profile to make it stick.

In fact the solution was simpler than the above for me, I just had to put

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home

in my tomcat startup script (since I only needed the 1.6 jvm in tomcat).

,

  1. No comments yet.
(will not be published)


css.php