Question

I have 2 java versions on my computer:

/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

The 1.6.0 is set to default. How can I make my java programs to run 1.7?

Tried to add:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

to my .zshrc file. But this seems to only change the path for my terminals java command.

Also tried to change the HOME symlink like this:

cd /Library/Java
mv Home Home-1.6
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home

This had no effect at all.

Also tried java changer software: http://www.guigarage.com/2013/02/change-java-version-on-mac-os/ But no effect.

Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?

Was it helpful?

Solution

I believe OS X (at least 10.8) uses the following paths:

  • JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
  • JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

Those are symlinks, which you can update to point to your 1.7 installation.

You can verify this fairly easily:

a) run which java to check which java executable is being executed. In theory, that should be /usr/bin/java.

b) run ls -la on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java on my machine).

I think this should sort your .jar execution issue. If your Java application is wrapped in a .app, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub being used by the .app.

OTHER TIPS

$ edit ~/.profile

#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}


$ java -version

java version "1.8.0_20-ea"

here are the steps:

http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html

You can always add into your profile both on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home

This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top