11

I am developing an aplication in cocoa which uses some java classes .I am getting an error "JAVA_HOME is not defined correctly We cannot execute /System/Library/Frameworks/JavaVM.framework/Home/bin/java".I dont know how to resolve this..Please anyone help me..

Thanks in advance

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
MobX
  • 2,640
  • 7
  • 33
  • 54

6 Answers6

25
export JAVA_HOME=`/usr/libexec/java_home` is exactly what you want to do.

In fact, all of the Apache projects (well, any project really) that hardcodes /System/Library/Frameworks/JavaVM.framework/Versions/... needs to use /usr/libexec/java_home if it exists. It's the only way you will know if Java is actually installed.

At some point in the future the symlinks in /System/Library/Frameworks/JavaVM.framework/Versions/ will be going away, which will even more severely break these projects if they want to load using an Oracle/OpenJDK JVM.

Alex
  • 251
  • 3
  • 3
2

Set JAVA_HOME to point to the .../Home directory, not the java binary. E.g.

export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home

Why are you setting the environment variable in the first place? You shouldn't have to do this on OS X...

liwp
  • 6,746
  • 1
  • 27
  • 39
2

In your .bashrc file, add below lines:

export JAVA_HOME=/usr
export PATH=$PATH:$JAVA_HOME

This worked for me.

Shrutee
  • 1,805
  • 1
  • 12
  • 13
2

Add the following line to ~/.mavenrc file

export JAVA_HOME=$(/usr/libexec/java_home)

Reference: Maven ignoring JAVA_HOME on OSX?

Community
  • 1
  • 1
shaunthomas999
  • 5,544
  • 2
  • 26
  • 30
0

Some times changing Java_HOME does not help, because in apache ant script the java_home is hardcoded. If when you change the JAVA_HOME still failed to run ant, you can try to change the default hardcode to your JAVA_HOME in ant script, like:

    $ vi /Users/apache-ant-1.8.3/bin/ant 
    #ant from line 83 to 93
    case "`uname`" in
      CYGWIN*) cygwin=true ;;
      Darwin*) darwin=true
               if [ -z "$JAVA_HOME" ] ; then
 #delete JAVA_HOME=XXXXX(default line) , and give JAVA_HOME ur java home url       




JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
                           fi
                           ;;
                  MINGW*) mingw=true ;;
                esac
C B
  • 1,677
  • 6
  • 18
  • 20
0

This can also happen because of the misconfigured jenv, in case it is installed.

In the ~/.bash_profile, there should be these 3 lines:

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
eval "$(jenv enable-plugin export)"

Then reload it by: source ~/.bash_profile

Nikita
  • 1,811
  • 1
  • 20
  • 41