开发者

JAVA_HOME is not defined correctly Error while compiling

开发者 https://www.devze.com 2022-12-18 01:04 出处:网络
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/j

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开发者_如何学JAVA..Please anyone help me..

Thanks in advance


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.


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


In your .bashrc file, add below lines:

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

This worked for me.


Add the following line to ~/.mavenrc file

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

Reference: Maven ignoring JAVA_HOME on OSX?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号