Setting the correct Java version under MacOS X

Share this post:

My favorite scripting language is CFML, or as some know it as ColdFusion. I like it because it is very very powerful, easy to use and can do just about everything your xyz language can do.

For many years, ColdFusion was a closed sourced system, where the former Macromedia and now Adobe got the copyright of the code. Luckily, this has changed when OpenBlueDragon (OpenBD) came to play with the first open source CFML application server. So, now the CFML world got a very nice open source CFML language and server. Our very own open source Digital Asset Management – Razuna – runs on OpenBD as well and comes bundled with it.

Anyhow, the reason of this blog post is not CFML, but how to set the correct Java JRE environment under MacOS X. Then why did I mention CFML and OpenBD in the first place, you might ask?

Well, today I downloaded the latest version of OpenBD which runs now on Java 1.6 and is 64 bit. But when I tried to start our server (Tomcat) with the new OpenBD jar I got the following error messages in the log.

at org.apache.catalina.startup.
Bootstrap.main(Bootstrap.java:413) Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.naryx.tagfusion.cfm.application.cfHttpSessionListener)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal (WebappClassLoader.java:1854)

As we can see from the “Bad version number…” in the above line there must be some misconfiguration of the Java runtime going on. But wait, does my execution of “java -version” not state that I’m running the latest Java version? Reading from those lines, you could think so.

java version “1.6.0_13”
Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211)
Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode)

Apparently when one looks into the Java paths of MacOS X we see that the current “JDK” is set to 1.5 and not 1.6. Judging from this, I tend to think that Apple is not setting the JDK right for Java applications. You might say, well then just set it in the “Java Preferences”, right? Wrong, I already did that as the screen below shows).

Java Preferences

So, in order to solve this, I set the correct JRE_HOME variable in my .profile in order for all Java applications to pick up the current JRE. To do that, you simple edit your .profile (with vi ~/.profile) and add the following lines to it:

JRE_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
export JRE_HOME

Save it, open a new terminal window (or close and open one) and start Tomcat. Now Tomcat is picking up the new JRE path and Java application, in my case OpenBD, that depend on the Java 1.6 JRE version will run.

Over 10 years in business.

Self-funded. No investors. No bullshit.

More than 3,000 customers worldwide.

Helpmonks - no bullshit customer engagement service

Growth starts with action

Empower your team and delight your customers.

Helpmonks - email management for small businesses