Many Java applications that use shell scripts to configure their environment use the JAVA_HOME
environment variable to start the correct version of Java, locate JRE JARs, and so on.
On OSX 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
I've found this stack to help, i was having the same issue and i could fix:
My java path was here:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and was needed to put into my
.bash_profile
:export JAVA_HOME=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"
Hope help
Create file
~/.mavenrc
then paste this into the file
export JAVA_HOME=$(/usr/libexec/java_home)
test
mvn -v
Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile:
export PATH=${JAVA_HOME}/bin:$PATH
P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc
Skipping Terminal setup since you mentioned applications, permanent system environment variable set up (works for macOS Sierra; should work for El Capitan too):
(this will set JAVA_HOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. javac 1.8.0_101, javac 1.8.0_131)
Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system
Does Snow Leopard still have
/usr/libexec/java_home
? On 10.5, I just setJAVA_HOME
to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my.bashrc
file, which sets this variable:I haven't experienced any problems with that technique.
Occasionally I do have to change the value of
JAVA_HOME
to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I setJAVA_HOME
by running:For those of you who don't have
java_home
in your path add it like this.That above works not any more in YOSEMITE for GRAPHICAL APPLICATIONS! Like eclipse, or anything started with Spotlight. (.bash_profile, launchd.conf works for terminal sessions only.) Before starting eclipse, just open a terminal window, and give out the following command:
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
(With your installation path! Perhaps works with $(/usr/libexec/java_home) instead of the full path too.)
View the whole excellent article about the permanent solution here: Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?