Java 7 and Groovy on Mac OS X Mountain Lion

I usually keep all my softwares and SDKs to the latest version but jdk7 was probably amongst the longest resisted update/upgrade. Mostly running groovy, I never got motivated enough to upgrade and then there have been several security and compatibility issues reported by many.

Anyways, today I just thought of doing it, primarily to reap benefits of invokedynamic, the thing I have not even looked at so far. The download was pretty simple in form of a .dmg and then the .pkg installer.

I fired up terminal with to check java and viola:
kunal@kaydee $ java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

The second natural thing was to just verify groovy, but what the heck, the JVM version I see is:
kunal@kaydee $ groovy -version
Groovy Version: 2.0.6 JVM: 1.6.0_37 Vendor: Apple Inc. OS: Mac OS X

Apparently Java 7 got installed at

But the one available to groovy was something else:
kunal@kaydee $ groovysh
Groovy Shell (2.0.6, JVM: 1.6.0_37)
===> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

Setting JAVA_HOME Environment variable comes to rescue (in .zshrc or .bash_profile or whatever profile file you use.)
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home"

Reload the iTerm and

kunal@kaydee $ groovy -version
Groovy Version: 2.0.6 JVM: 1.7.0_11 Vendor: Oracle Corporation OS: Mac OS X

1 comment:

akshay bhatt said...

Ubuntu(debian) users can make switch between Java versions using :

sudo update-alternatives --config java

Life can't be more fun.