Update: This post refers to OS X 10.5 “Leopard”, if you are using 10.6 “Snow Leopard”, you might want to consider reading my post “Java and Snow Leopard” instead.
I just started using my Mac as a development machine and thought I’d share some of the issues and solutions I came across. I’m using Java 6, Tomcat 6, Eclipse 3.3.2 (Europa), hibernate 3, Spring 2.0.3 and tapestry 1.4.5.
The first issue I came across was an
UnsupportedClassVersionError: Bad version number in .class file
error when I tried to start tomcat. (I’m using the sysdeo plug-in to control tomcat, even though I’m aware that WTP is much better… I have my reasons, but that’s beyond the scope of this post.)
Now the title of the console in Eclipse revealed the problem, the Sysdeo plug-in was using version 1.4 of the Java RE. The thing is, I didn’t notice this until I tried a whole bunch of other stuff… which cost me quite a bit of time, but also helped understand a few things better.
OS X keeps the different Java versions neatly separated in the
directory. By creating or overwriting the symbolic link “CurrentJDK”, you can change the default JDK version of your system. To do this, you have to change to the Versions directory and set a new symlink with ln:
$cd /System/Library/Frameworks/JavaVM.framework/Versions $sudo ln -fhsv 1.6 CurrentJDK
After providing the administrator password, the default JDK will be set to version 1.6. Unfortunately, after doing this, I couldn’t start Eclipse anymore. The fix for this is to edit the following file:
and un-comment the following line:
This tells Eclipse to use a specific Java version, instead of the platforms default one. Now I was able to start Eclipse again and tomcat started without exceptions when I manually deployed my war files. My next step was to try Sysdeo to start Tomcat, which is where I realized that all I would have had to do was to set the correct JVM in Preferences > Tomcat > JVM Settings. Anyway, learned something on the way
Here are some links that helped me: