in Technology

Setting JAVA_HOME on Mac OS X 10.5

I have been playing around with a lot of Java tools these days! I was trying out XPlanner and when I ran the startup shell script, it spit out the infamous error!

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

I tried a couple of things, but they did not work. A bit of Google, and found an easy way.

Here are the steps!

  • Open Terminal.
  • First confirm you have JDK by typing “which java”. It should show something like /usr/bin/java.
  • Check you have the needed version of Java, by typing “java -version”. My setup shows java version “1.5.0_13”
  • JAVA_HOME is essentially the full path of the directory that contains a sub-directory named bin which in turn contains the java.
  • For Mac OSX – it is /Library/Java/Home (There are other directories too, but this is the simplest!)
  • Set JAVA_HOME using this command in Terminal: export JAVA_HOME=/Library/Java/Home
  • echo $JAVA_HOME on Terminal to confirm the path
  • You should now be able to run your application

This sets JAVA_HOME only for this session. If you want it to persist, you will have to add the command to your ~/.profile file.

For more details on this, refer to Sean Brown’s blog post.

Write a Comment

Comment

11 Comments

  1. Thanks to both of you (you and Sean) for this. I needed to get Jetty up and running, and my lack of knowledge about the java environment was making me fail on this seemingly innocuous little thing… Thanks again! 🙂

  2. Don’t hardcode a path to /Library/Java/Home. Instead you should use:
    export JAVA_HOME=`/usr/libexec/java_home`
    This will dynamically pick the top JVM from list in the Java Preferences app.

  3. Thanks! BTW, it’s actually /Library/java/Home (lower case j) on 10.6.x or you will have problem running Tomcat.

  4. You could also have these env. variables set for you on start up so its consistent by creating a .plist file which is an XML format file u can create it with Xcode. save this file in ~/.MacOSX/environment.plist and in the plist its a key-value style.

Webmentions

  • Setting JAVA_HOME on Mac OS X | Kev's Development Toolbox July 16, 2012

    […] post here talks about the first approach, but there’s a comment in response to the post that points out […]

  • Getting Started with JBoss and Seam | DeepElement July 16, 2012

    […] Resolution: http://www.mehtanirav.com/2008/09/02/setting-java_home-on-mac-os-x-105 […]

  • Deploying Content Transcoder « David’s Blog July 16, 2012

    […] may also need to set the environment variable JAVA_HOME.  On OS X you may find this guide helpful.  On Windows Right click computer->properties and go to the Advanced tab. Select […]