Entrepreneur Geek

Nirav Mehta on life, technology and future

Setting JAVA_HOME on Mac OS X 10.5

with 7 comments

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.

Related posts:

  1. Setting up local copy of PHP manual – with smart lookups If you are a PHP developer, you probably know that...
  2. Finding number of lines in files recursively I wanted to find the number of lines from a...

Written by Nirav

September 2nd, 2008 at 1:18 pm

Posted in Apple

Tagged with

 

7 Responses to 'Setting JAVA_HOME on Mac OS X 10.5'

Subscribe to comments with RSS or TrackBack to 'Setting JAVA_HOME on Mac OS X 10.5'.

  1. End of year thanks: this post is the number one referring link (non-search) to my blog.

    Sean M. Brown

    22 Dec 08 at 9:51 am

  2. 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! :)

    Evan

    10 Apr 09 at 10:09 am

  3. Very Helpful

    Thanks alot.

    Vamshi

    22 Jul 09 at 1:36 am

  4. 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.

    Mike Swingler

    26 Aug 09 at 7:55 pm

  5. Thanks alot, it helped me alot

    Murali

    20 Sep 09 at 11:43 pm

  6. Thanks for this post, It removed my confusion.

    Kanisk

    10 Feb 10 at 5:34 am

  7. I figured out the
    export JAVA_HOME=`/usr/libexec/java_home`
    myself, but thanks for the confirmation .

    Joseph Toman

    12 Feb 10 at 2:53 am

Leave a Reply