JAVA_HOME error while maven build, OSX-10.8.4 Version Error: JAVA_HOME is not defined correctly.
  We cannot execute
  /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java


I have upgraded my OSX to 10.8.4. After OSX upgrade I have upgraded my JDK and JRE to 7. But I am getting the above error when I am trying for maven build of project. 

When I run ls -al /System/Library/Frameworks/JavaVM.framework/Versions/

I get the below response

drwxr-xr-x  11 root  wheel  374 Jul 22 22:33 .
drwxr-xr-x  10 root  wheel  340 Jul 22 18:30 ..
lrwxr-xr-x   1 root  wheel   10 Jul 22 18:30 1.4 -&gt; CurrentJDK
lrwxr-xr-x   1 root  wheel   10 Jul 22 18:30 1.4.2 -&gt; CurrentJDK
lrwxr-xr-x   1 root  wheel   10 Jul 22 18:30 1.5 -&gt; CurrentJDK
lrwxr-xr-x   1 root  wheel   10 Jul 22 18:30 1.5.0 -&gt; CurrentJDK
lrwxr-xr-x   1 root  wheel   10 Jul 22 18:30 1.6 -&gt; CurrentJDK
lrwxr-xr-x   1 root  wheel   10 Jul 22 18:30 1.6.0 -&gt; CurrentJDK
drwxr-xr-x   7 root  wheel  238 Jul 22 18:30 A
lrwxr-xr-x   1 root  wheel    1 Jul 22 18:30 Current -&gt; A
lrwxr-xr-x   1 root  wheel   59 Jul 22 18:30 CurrentJDK -&gt; /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents


For this ls -al /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin

I don't see any contents in CurrentJDK further.

On running /usr/libexec/java_home

I get:

/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home


I am pretty much new to working with OS X. Let me know if I might have missed any point still in making it successful.
Apple recommends to set JAVA_HOME to “/usr/libexec/java_home“. 

What worked for me was wrapping this around $(). So I ended up configuring JAVA_HOME like $(/usr/libexec/java_home) with the following commands:

vim ~/.bash_profile 
export JAVA_HOME=$(/usr/libexec/java_home)
source ~/.bash_profile