Switching J2SE versions on Mac OS (SnowLeopard) - java

My current JDK on Mac OS (10.6) is set to 1.6 and I'd like to switch to 1.5.
A listing of '/System/Library/Frameworks/JavaVM.framework/Versions/' shows:
lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Nov 3 18:34 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 5 Nov 3 18:34 1.6 -> 1.6.0
drwxr-xr-x 8 root wheel 272 Nov 3 19:54 1.6.0
drwxr-xr-x 9 root wheel 306 Nov 3 19:54 A
lrwxr-xr-x 1 root wheel 1 Nov 3 18:34 Current -> A
lrwxr-xr-x 1 root wheel 3 Nov 3 18:34 CurrentJDK -> 1.6
Aside from attempting to install 1.5 and then change the symlink for 'CurrentJDK' from 1.6 to 1.5, is there anything else that needs to be done?
Do I also need to change what 'Current' is pointing to? The 'A' directory seems to contain the Headers and the binary executables (javac, jar, etc).
Will another version of the JDK install a second directory for it's version of the executables (hopefully in a separate directory) or are they independent of the JDK version?
FYI: I've run the 'Java Preferences' utility and only Java SE 6 (32 & 64-bit versions) is listed under both 'Java Apple Plugin' and 'Java Applications'

There is no supported means of getting a real 1.5 onto SnowLeopard. There are ways to make it work if you are brave.
See this discussion
The Guts Of The Matter Are Here

Related

JDK still pointing to 1.6 on Mac OSX 10.10.2

So I have been trying to compile my code and I get the following error:
Information:Using javac 1.7.0_80-ea to compile java sources
Information:java: Errors occurred while compiling module 'DataRegistry'
Information:4/8/15, 9:48 AM - Compilation completed with 14 errors and 0 warnings in 2 sec
/Users/jvy234/Documents/workspace/dataregistry/src/main/java/com/capitalone/hub/registry/controller/SandboxController.java
Error:(169, 43) java: diamond operator is not supported in -source 1.6
(use -source 7 or higher to enable diamond operator)
I manually forced the CurrentSDK symlink to java 1.7:
6003088f811e:~ jvy234$ which java
/usr/bin/java
6003088f811e:~ jvy234$ ls -ltr /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Jan 21 09:52 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
6003088f811e:~ jvy234$ ls -ltr /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
lrwxr-xr-x 1 root wheel 10 Jan 21 09:52 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jan 21 09:52 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jan 21 09:52 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jan 21 09:52 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jan 21 09:52 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jan 21 09:52 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 1 Jan 21 09:52 Current -> A
drwxr-xr-x 7 root wheel 238 Jan 21 09:52 A
lrwxr-xr-x 1 root wheel 59 Apr 8 09:43 CurrentJDK -> /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/
When I go to my Preferences panel for Java I see Java 1.7_80 installed. What can I do to make it use JDK 1.7 ?
You can change the jdk used to compile your project in File/Project Structure/SDKs/Java SDK (see here).
If you wish to change the compiler of your entire workspace, you can change the compiler used in File/Settings/Build, Execution, Deployment/Compiler/Java Compiler (see this doc page).
If you still get the same error message, you can pass -source 7 in the javac options.

Java 1.7 on OSX 10.9.2 running as 1.5?

Pulling my hair out about this one. java -version and javac -version both report the same 1.7.0_45, but when I try to compile the simplest class I get a class file error:
> cat A.java
public class A {}
> javac A.java
A.java:1: cannot access java.lang.Object
bad class file: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/rt.jar(java/lang/Object.class)
class file has wrong version 51.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
public class A {}
^
1 error
There certainly is no JDK 1.5 installed. I don't think there even is a 1.5 JDK that runs on OSX any more.
FWIW, here's the frameworks directory containing the "versions" and stub executables:
> ls -al /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
drwxr-xr-x 11 root wheel 374 28 Mar 09:03 .
drwxr-xr-x 12 root wheel 408 11 Mar 07:52 ..
lrwxr-xr-x 1 root wheel 10 29 Oct 12:54 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 29 Oct 12:54 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 29 Oct 12:54 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 29 Oct 12:54 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 29 Oct 12:54 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 29 Oct 12:54 1.6.0 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 28 Mar 09:03 A
lrwxr-xr-x 1 root wheel 1 29 Oct 12:54 Current -> A
lrwxr-xr-x 1 root wheel 1 28 Mar 09:03 CurrentJDK -> A
I've checked the usual suspects, there's no JAVA_HOME or CLASSPATH environment variables, not that it matters when there's no 1.5 installed. I also get the exact same behaviour if I install JDK 8.
Does anybody have an idea what's causing this?
OK, thanks to this post (Java compilation error: Mac) I found the solution:
rm -rf ~/Library/Java/Extensions
sudo rm -rf /Library/Java/Extensions

Mac OSX Java Terminal version incorrect

Ok, I'm a bit new to Macs and OSX, but I picked one up so that I can do some troubleshooting on my Java programs with one since the company I work for uses a combination of OSX and Windows machines. The problem I'm running into is, when I install Java 7 from Oracle's website, it updates the preferences menu and appears to execute .jar files correctly when double-clicking them, but the terminal window's version is still 1.6.0_43 and running the same .jar file from the terminal results in runtime errors due to the older version.
When I navigate to /Library/Java/JavaVirtualMachines/ I'm presented with an empty folder. From what I've seen in other articles, this is where the Java 1.7.0's version folder should be. Any idea what's going on? How can I get the terminal to use the correct version of Java?
Edit: #DWilches comment on his original answer:
(1)
total 64
lrwxr-xr-x 1 root wheel 10 Mar 17 21:38 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 17 21:38 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 17 21:38 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 17 21:38 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 17 21:38 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 17 21:38 1.6.0 -> CurrentJDK
drwxr-xr-x 8 root wheel 272 Mar 17 21:38 A
lrwxr-xr-x 1 root wheel 1 Mar 17 21:38 Current -> A
lrwxr-xr-x 1 root wheel 59 Mar 17 21:38 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
(2)
ls -ld /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Mar 17 21:38 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
Edit: sorry for the mistake with a new answer, gotten too used to sites that block edits of the original post after so long...
JDK
On Mac OS, /usr/bin/java and friends are stubs that delegate to the real JDK commands. These stubs respect the setting of your JAVA_HOME environment variable, but for this to work you need to install the JDK (from http://www.oracle.com/technetwork/java/javase/downloads/index.html) as opposed to the JRE (from http://java.com).
The JDK installs into /Library/Java/JavaVirtualMachines/jdk1.7.0_NN.jdk (for whatever value of NN), so set your JAVA_HOME environment variable to /Library/Java/JavaVirtualMachines/jdk1.7.0_NN.jdk/Contents/Home to make /usr/bin/java use 1.7. You can switch back to 1.6 simply by pointing your JAVA_HOME to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home instead. You can use the /usr/libexec/java_home tool to find the right value automatically, for example to make /usr/bin/java use Java 7 you can do
export JAVA_HOME=`/usr/libexec/java_home -v '1.7*'`
and to make it use Java 6 you can do
export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`
The same applies to Java 8 (using -v '1.8*'). This will pick up the latest installed JDK for the relevant major version, you don't need to remember to change the NN by hand when you install an update.
JRE
If you want to run the 1.7 or 1.8 JRE from the command line, it can be found in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java. This is a fixed path and you can only have one "public" JRE installed at any given time.
$ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
You could use a shell alias in your .bashrc
alias java_jre='/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java'
The issue is that Oracle's JRE installation does not change the /usr/bin/java executable. If you want to use this Java you have to use the path under /Library (need to find what this is I have JDK install so could be different)
As per Oracle's JRE installation document
Installing a JRE from Oracle will not update java -version symlinks or
add java to your path. To be able to do this, you need to install the
JDK.
The Oracle JDK does change /usr/bin/java to point to the Java 7 executable. If you are doing development then you should use this as it includes more than the JRE.
The Oracle install FAQ says
Q: Should I install the JRE or the JDK?
A: If you plan to run Java applications, install the Java Runtime
Environment (JRE). The JRE is also referred to as Oracle Java. Once
you have installed the JRE, you can launch Java applets and
applications by double-clicking JAR files, JNLP files, and via the
browser. Note that 32-bit browsers, such as Firefox in 32-bit mode,
and Chrome, are not supported by the JRE.
If you plan to write Java applications, install the Java Development
Kit (JDK).
First, did you Quit the Console and open it again so it has chances of taking the changes in the PATH variable ?
If you've already done this, then check which the default version of your Java is:
dwilches# ~$ cd /System/Library/Frameworks/JavaVM.framework/Versions/
dwilches# Versions$ ls -l
lrwxr-xr-x 1 root wheel 59 Mar 19 10:07 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
lrwxr-xr-x 1 root wheel 10 Mar 19 10:07 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 19 10:07 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 19 10:07 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 19 10:07 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 19 10:07 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Mar 19 10:07 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 1 Mar 19 10:08 Current -> A
drwxr-xr-x 8 root wheel 272 Mar 25 10:03 A
Now, you can see that the "Current" version is "A" (that's my Java7). If I would like to change it to Java 1.6 then I could write:
dwilches# Versions$ sudo unlink Current
dwilches# Versions$ sudo ln -s 1.6 Current
And then:
dwilches# Versions$ java -version
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-11M4203)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)
So you may use this to make "Current" point to your desired Java location.
Just like Ian said, but probably you want java7 to be called from .sh script, so you need a function instead of alias added to .bash_profile:
java7() {
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java "$#"
}
export -f java7

Where is Oracle's (Sun's) JDK/JRE installed on Mac OS X 10.8 Mountain Lion?

Where does Oracle (Sun) install their JDK/JRE on Mac OS X 10.8 Mountain Lion?
/Library/Java/JavaVirtualMachines/ according to the Mac JDK Uninstall Docs.
The Oracle Java SE downloads at: http://www.oracle.com/technetwork/java/javase/overview/index.html
install here on Maverick at least:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/
this JRE is entirely separate from the ones that Apple has installed, which are under /System/Library/Frameworks/JavaVM.framework/Versions/ as another answer mentioned.
If you setting the JRE path in something like Eclipse you'll need to point to the /home directory i.e
/Library/Java/JavaVirtualMachines/<Replace with version>/Contents/Home
Some of the other answers might be correct but this is what worked for me (which is different and up to date as of January 2016) when installing it on a new computer at the office.
The path as mentioned in another answer is
/Library/Java/JavaVirtualMachines/<Replace with version>/Contents/Home
Here however is a visual guide to getting there, because you can find many directories named "Library". Make sure you are here
then click into JavaVirtualMachines
If you are doing a new setup and just downloaded Android studio, they might have sent you to "Download Java for OS X 2015-001" at https://support.apple.com/kb/dl1572?locale=en_US That gives you version 1.6.0
That won't work!!!!
I got the error that I needed JDK 7.0 or newer.
I looked for a newer version and found this link from Oracle
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
I installed it, then selected that one. And it worked
On my system, evaluating which java leads me to /usr/bin/java. This in turn is a symlink to:
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
In case it's relevant, java -version tells me I have 1.6.0_37 installed.
The JDK/JRE as mentioned in previous answers is located in /Library/Java/JavaVirtualMachines/<version>/Contents/Home/. The JRE is dir under this Home.
Interestingly browsers doesn't use files from this location for java applet plugin. The location used by browsers is /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/.
In fact if you run JRE installer, it updates the files in this location rather than JDK/JRE location.
Enough answers here, but I'm JUST adding a way to find it by yourself
$ sudo find / -name Java
/Library/Application Support/Oracle/Java
/Library/Java
/private/var/root/Library/Application Support/Oracle/Java
/System/Library/Java
/Users/prayagupd/Library/Application Support/Oracle/Java
To be more specific,
$ sudo find / -name jdk*
/Applications/Android Studio.app/Contents/jre/jdk
/Applications/Android Studio.app/Contents/lib/jdkAnnotations.jar
/Applications/IntelliJ IDEA.app/Contents/jre/jdk
/Applications/IntelliJ IDEA.app/Contents/lib/jdkAnnotations.jar
/Library/Java/JavaVirtualMachines/jdk1.7.0_76.jdk
You see /Library/Java/JavaVirtualMachines/ is the place you need to look inside.
And /Library/Java/JavaVirtualMachines/jdk<version>.jdk/Contents/Home/ is your JAVA_HOME
$ ls -ls /Library/Java/JavaVirtualMachines/jdk1.7.0_76.jdk/Contents/Home/
total 39776
8 -rw-rw-r-- 1 root wheel 3339 Dec 18 2014 COPYRIGHT
8 -rw-rw-r-- 1 root wheel 40 Dec 18 2014 LICENSE
8 -rw-rw-r-- 1 root wheel 114 Dec 18 2014 README.html
216 -rw-rw-r-- 1 root wheel 110114 Dec 17 2014 THIRDPARTYLICENSEREADME-JAVAFX.txt
344 -rw-rw-r-- 1 root wheel 173559 Dec 18 2014 THIRDPARTYLICENSEREADME.txt
0 drwxrwxr-x 44 root wheel 1496 Feb 28 20:13 bin
0 drwxrwxr-x 9 root wheel 306 Feb 28 20:13 db
0 drwxrwxr-x 9 root wheel 306 Feb 28 20:13 include
0 drwxrwxr-x 10 root wheel 340 Feb 28 20:13 jre
0 drwxrwxr-x 14 root wheel 476 Feb 28 20:13 lib
0 drwxrwxr-x 5 root wheel 170 Dec 18 2014 man
8 -rw-rw-r-- 1 root wheel 502 Dec 18 2014 release
39184 -rw-rw-r-- 1 root wheel 20061067 Dec 18 2014 src.zip
The version 8 release from Oracle (1.8.0_40-b25) can be found at:
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java
FYI: Oracle is not following the practice of making /Library/Java/Current (etc) a link to the latest installed java.
Below is my method of keeping up with versions over time: from my .zshrc file:
108 JAVA_6_HOME=/System/Library/Frameworks/JavaVM.framework/Home
109 JAVA_7_HOME=/Library/Java/Current
110 JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
111
112 export JAVA_6_HOME
113 export JAVA_7_HOME
114 export JAVA_8_HOME
115
116 export JAVA_HOME=$JAVA_8_HOME
117
118 PATH=$PATH:$JAVA_HOME/bin
119

Java5 on Snow Leopard

I need Java5 (not 6), but Snow Leopard comes with only Java6.
There is /System/Library/Frameworks/JavaVM.framework/Versions/1.5, but that just points to 1.6.0:
$ ls -la /System/Library/Frameworks/JavaVM.framework/Versions/
lrwxr-xr-x 1 root wheel 5 Sep 24 20:12 1.3 -> 1.3.1
drwxr-xr-x 3 root wheel 102 Jul 21 07:35 1.3.1
lrwxr-xr-x 1 root wheel 10 Sep 24 20:12 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Sep 24 20:12 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 5 Sep 24 20:12 1.6 -> 1.6.0
drwxr-xr-x 7 root wheel 238 Sep 24 20:12 1.6.0
drwxr-xr-x 8 root wheel 272 Sep 24 20:12 A
lrwxr-xr-x 1 root wheel 1 Sep 24 20:12 Current -> A
lrwxr-xr-x 1 root wheel 3 Sep 24 20:12 CurrentJDK -> 1.6
Can I install the real 1.5 from somewhere?
Here is a link to downgrading Snow Leopard to Java 1.5
Hmm, i do not have installed 10.6 yet (it is on the way), but the versions directory looks strange. Where is 1.4? And no version should point to CurrentJDK! My 10.5 installation is the following:
r2d2:~ arne$ ls -l /System/Library/Frameworks/JavaVM.framework/Versions
total 56
lrwxr-xr-x 1 root wheel 5 16 Sep 19:14 1.3 -> 1.3.1
drwxr-xr-x 3 root wheel 102 14 Jan 2008 1.3.1
lrwxr-xr-x 1 root wheel 5 16 Sep 19:14 1.4 -> 1.4.2
lrwxr-xr-x 1 root wheel 3 21 Feb 2008 1.4.1 -> 1.4
drwxr-xr-x 8 root wheel 272 21 Feb 2008 1.4.2
lrwxr-xr-x 1 root wheel 5 16 Sep 19:14 1.5 -> 1.5.0
drwxr-xr-x 8 root wheel 272 21 Feb 2008 1.5.0
lrwxr-xr-x 1 root wheel 5 16 Sep 19:14 1.6 -> 1.6.0
drwxr-xr-x 8 root wheel 272 26 Sep 2008 1.6.0
drwxr-xr-x 8 root wheel 272 16 Sep 19:14 A
lrwxr-xr-x 1 root wheel 1 16 Sep 19:14 Current -> A
lrwxr-xr-x 1 root wheel 3 16 Sep 19:14 CurrentJDK -> 1.5
r2d2:~ arne$
Do other 10.6 users have the same problem? I am not shure about installing the Java 5 package for 10.5 will work on 10.6. Someone have experience?
Run java5 on Snow Leopard
Get the java 5 that was included in 10.5 "leopard" and unpack
cd /tmp/
curl -o java.1.5.0-leopard.tar.gz
http://www.cs.washington.edu/homes/isdal/snow_leopard_workaround/java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz
Move it to your System java folder (password needed)
sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard
Tell OS X that java 5 actually is java 5
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo ln -s 1.5.0-leopard 1.5.0
sudo rm 1.5
sudo ln -s 1.5.0 1.5
I've put together a small how-to here.
I was receiving a 'Bus Error' when trying to use the steps at http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard on 10.6.6. However when I tried
Sagacity's steps above. I was able to get 1.5 to run.

Categories