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.
Related
I just read here, that the Java DB (respectively Derby) is shipped with the JDK.
Where is the derby.jar within the Java installation on my Mac?
The terminal command
/usr/libexec/java_home
prints
/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
and
ls -halt /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
drwxr-xr-x 10 root wheel 320B 6 Okt 14:29 .
drwxr-xr-x 5 root wheel 160B 6 Okt 14:29 ..
-r--r--r-- 1 root wheel 160B 6 Okt 14:29 README.html
drwxr-xr-x 34 root wheel 1,1K 6 Okt 14:29 bin
drwxr-xr-x 7 root wheel 224B 6 Okt 14:29 conf
drwxr-xr-x 9 root wheel 288B 6 Okt 14:29 include
drwxr-xr-x 72 root wheel 2,3K 6 Okt 14:29 jmods
drwxr-xr-x 72 root wheel 2,3K 6 Okt 14:29 legal
drwxr-xr-x 57 root wheel 1,8K 6 Okt 14:29 lib
-rw-r--r-- 1 root wheel 1,2K 6 Okt 14:29 release
The only jar file within the Home folder I can find is the following:
find . -name '*.jar'
./lib/jrt-fs.jar
Thank you for your help!
P.S.:
java -version
prints
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
As of JDK 9, Derby is no longer included in the JDK. From the migration guide:
JavaDB, which was a rebranding of Apache Derby, isn’t included in JDK 9.
JavaDB was bundled with JDK 7 and JDK 8. It was found in the db directory of the JDK installation directory.
You can download and install Apache Derby from Apache Derby Downloads.
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
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
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
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.