8

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?

2
  • what does the terminal say if you type java -version? Commented Sep 27, 2013 at 9:15
  • 3
    closed as off topic? "...unless they directly involve tools used primarily for programming." The jdk is almost exclusively used for programming. Commented Dec 6, 2013 at 21:14

3 Answers 3

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I think that last part is the actual answer to the problem: "version of java used will depend on the JavaApplicationStub being used by the .app.". Guess it´s me doing wrong when using Jar Bundle(no 1.7 support....)
In that case, this might be of interest.
2
$ 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

1 Comment

Try to add some of the detailed steps from the link...future users may not have access to it.
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.