Selected Java version 8 is not supported by SDK (Maximum 7) - spring-boot

New project => Sprint Initiliazr. After leaving everything to the default settings, and clicking next, the error below shows:
Selected Java version 8 is not supported by SDK (Maximum 7)
See the image here
I've tried to update Java and installing AdoptOpenJDK as well as restarting the computer but that didn't help.

Try at first following the JDK setup guide and installing the Jetbrains JDK: Selecting the JDK version the IDE will run under.
If this doesn't help, select at the project creation the appropriate Jetbrains JDK manually. The Jetbrains JDK was downloaded on your machine by the Choose Runtime Plugin (as mentioned in the guide).
In Windows it's located in your user folder e.g.:
C:\Users\xxxx\.IntelliJIdea201x.x\config\jdks\jbsdkxxxx...
JDK Selection under Windows

Related

BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61 on Apple Arm

I have installed Android Studio Canary 2020.3.1.22 and trying to run Flutter project on Apple Silicon(ARM) Mac. Unfortunately, it is giving me this error when I try to run default flutter counter app.
Here is the error I am getting:
Could not open settings generic class cache for settings file '/Users/khamidjonkhamidov/StudioProjects/dummy/android/settings.gradle' (/Users/khamidjonkhamidov/.gradle/caches/6.7/scripts/f0emg6u6oecmxqzgk5g9nn4ui).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61
Gradle version: 6.7 but I tried 7+
JDK version 17
I would really appreciate your help)
According to the official grade docs: Java 17 and later versions are not yet supported.
You can check compatibility here.
So I have installed Java11 from Azul.
p.s. don't forget to change jdk version in Android studio
Preferences -> Build -> Build Tools -> Gradle -> Gradle JDK
Got the same error while I upgraded my build.gradle to Java 17. And the fix is as simple as we think:
Gradle starts supporting Java17 only from 7.3 release
Here's the complete reference for Java vs Gradle compatibility:
https://docs.gradle.org/current/userguide/compatibility.html
Upgraded my gradle to 7.3 in gradle-wrapper.properties.
https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
Some of you may experience now the Gradle dependency cache corrupt error after this like me. So better delete the gradle-wrapper.jar and reinstall it using the command:
./gradlew wrapper
Everything will work perfectly fine from here.
In case if you still face Gradle corrupt issue, please check whether you are using latest version of IDE especially Intellij.
First, you can execute this command: /usr/libexec/java_home -V, to retrieve all installed jdsk:
[~]$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
17.0 (x86_64) "Oracle Corporation" - "OpenJDK 17.0" /Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-17.0/Contents/Home
14.0.1 (x86_64) "Oracle Corporation" - "OpenJDK 14.0.1" /Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-14.0.1/Contents/Home
11.0.12.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/ciccio/Library/Java/JavaVirtualMachines/corretto-11.0.12/Contents/Home
10.0.2 (x86_64) "Oracle Corporation" - "Java SE 10.0.2" /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
1.8.0_302 (x86_64) "Amazon" - "Amazon Corretto 8" /Users/ciccio/Library/Java/JavaVirtualMachines/corretto-1.8.0_302/Contents/Home
Now, imagine you want to remove the version 17:
[~]$ java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment Homebrew (build 17+0)
OpenJDK 64-Bit Server VM Homebrew (build 17+0, mixed mode, sharing)
Go into the path of the version you want to remove (in this case "/Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-17.0/Contents/Home"), and delete entire folder: "/Users/ciccio/Library/Java/JavaVirtualMachines/openjdk-17.0".
Once removed, go back on terminal and use:
[~]$ /usr/libexec/java_home -v 14.0.1 --exec javac -version
javac 14.0.1
to force the new version to use (14.0.1).
Next check if is correct:
[~]$ java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+7)
OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
[~]$
Your Gradle now is back to work.
Basically, I installed jdk using brew install java which was not compatible with my current gradle I guess. So
I uninstalled java first using: brew uninstall java
installed JDK 8 or JDK 11 from azul.
Installed gradle: gradle-6.9-all.zip
When done, everything worked smoothly.
I found a way to fix this error without messing with the locally installed Java version or Gradle. Here is what I did:
If you are developing a Flutter project and got this error, go to File -> Close Project.
Then re-open from the android folder (omit this if you received from a pure Android project).
Now, Gradle may detect the issue on its own, and it will take a while to check. After it is done, it may provide upgrade steps in an upgrade assistant window at the bottom of the window along with logcat, build, terminal etc… which you need to accept and tell it to execute. Once it finishes, the error is resolved, and you are good to go.
If it does not seem to do anything on its own, then please open the Project Structure tab. Now select the latest Gradle version available that does not contain -rc (you don't want these, most of the time they are not stable releases).
Now select the JDK version that Gradle uses by going to Gradle (sidebar on the right of the window) -> Wrench Icon -> Gradle Settings. Select a compatible JDK version according to the Gradle project's documentation, as found HERE. Current latest stable version of Gradle is 7.4 with maximum supported JDK version 17 (also latest I believe if you use something like openJDK which I use), but Android Studio version at 7.1 so be careful.
Tested on MacBook Air M1 running macOS Monterey 12.2.1.
I faced this error when I updated my android studio
Solution:
you need to upgrade your distributionUrl According to the java version
‌Below is the Java version and Supported Gradle version
Check currently active java version:-
javac -version
If it is greater than 11 downgrade it to 11 or 8. Check your available java jdk version installed:-
/usr/libexec/java_home -V
If java 11 or 8 is not installed first install one of them using this link:- Download jdk 8
then change the default java version in .bash_profile
Edit .bash_profile
sudo nano ~/.bash_profile
Add 1.8 or 11 as default. (Add below line to bash_profile file)
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
OR
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
Now Press CTRL+X to exit the bash. Press 'Y' to save changes. And reload bash_profile
source ~/.bash_profile
Happened with newly created Flutter app in 2023 January with Mac Mini M1. If you have another working Flutter apps do not downgrade or update Java version as it will cause problem with all other working ones. Find gradle-wrapper.properities file inside gradle/wrapper folder (directly inside Android folder) and check gradle version. You just need to use newer version of gradle. I replaced this one and used flutter run command from terminal and it worked:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
With this one:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
No need to do anything else. Version number may be different for you depending on when you are trying this and what Java version you have.
Finally I Got the Solution
It is very easy to solve
step 1 : select the gradle version which support your java version link
step 2 : open your project navigate to your_project_name/android/gradle/wrapper/gradle-wrapper.properties
step 3 : in distributionUrl change the gradle version according to your java version
That's it No need to install older java versions
Happy coding
System: Mac M1, Android Studio Electric Eel (2022.1.1 Patch 1), JDK 19.02
I encountered this error when created a fresh project using flutter create and tried to run it in Android Studio.
Now I've got an interesting solution that worked for me:
Open the flutter project in Android Studio
Open build.gradle, the one under android folder
On the top right it shows "Open for Editing in Android Studio" (although it's already in Android Studio!). Click on that to open it for editing. I opened it in another window, but doesn't matter.
It starts to automatically download and update gradle to sync the build file. At one point, tt might also prompt you to upgrade gradle, which is good to do.
Done! Close the build.gradle and re-run the project. It should build and run fine.
I had this issue when I set the target for a new IntelliJ Kotlin project to be Java 17. My fix was to:
set the target to 9 in build.gradle.kt
close the project
delete the .gradle and .idea directories from the project folder
remove the project from the recent projects list
open the gradle file from IntelliJ and get it to rebuild everything
Open the Gradle settings and change the Gradle JVM to the same JDK version you are using.
(I am using 14.0.2)
This worked for me.
I had that Issue creating Projects from IntelliJ.
It seems the issue was the Gradle JVM Version.
Here is a configuration that works:
System:
Mac with ARM, Mac OS 12.1, M1 Max
java version 18.0.1-zulu
kotlin version 1.7.0
gradle version 7.5
I installed those version with sdkman https://sdkman.io/
and set the config manually on intellij (See attached Screenshot for Details)
IntelliJ Gradle JVM config
My solution was to open the android project in Android Studio. It detected the needed Gradle update and performed the update upon command.
I can't speak for everyone, but for me, I went into Flutter project's file android/gradle/gradle.properties, and changed the org.gradle.java.home value so that it pointed to a folder containing JDK 11 instead of JDK 18. That way, it used a JDK version that was actually supported.
On my side I fixed this issue by setting the default Java Version to 8 (download it if needed)
Mac:
Open Terminal.
open ~/.bash_profile
Add
# SWITCH TO JAVA VERSION 8
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
Save and restart Android Studio.
Giving my two seconds here...
In my case, I could fix it by finding my gradle version in the file gradle.wrapper.properties and checking the compatibility with the JDK, so I needed to install the JDK 16, so in my build.gradle(:app) I put this line of code inside the android {} :
compileOptions {
sourceCompatibility JavaVersion.VERSION_16
targetCompatibility JavaVersion.VERSION_16
}
After this I build my android version again, and it worked.
I ran into this issue on VSCode+Mac using the Gradle for Java extension.
My project uses Java 17 but Gradle was using JDK19, which I also had installed.
I removed the jdk-19.jdk folder from /Library/Java/JavaVirtualMachines and then ran the "Clean Java Language Server Workspace" task in VSCode.
After that, Gradle successfully built and I was even able to put the jdk-19 folder back and things continued to work.
Changing the Java Version in the Intellij resolved the issue.
Easy fix in 2023:
Command in the terminal:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Check classpath, current working one:
classpath 'com.android.tools.build:gradle:7.1.2'
Check gradle-wrapper.properities file:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
If still not solved you need to change Gradle JDK from inside Android Studio like below.
After that you can run fluter app directly from terminal without any issue. Note: Android Studio default JDK (11.0.15) does not work and causes this issue. Azul Zulu 16.0.2 works and solves the issue.
In my case, I use the react native cli and my android gradle is 7.3.1. I open the android folder in the android folder in the android studio and it suggests my gradle once after degradation it works fine
Windows Users
Open Android Studio and Click on Setting ICON far right. And Go to Project Structure Option and select the SDK's Version 11.0.15 and click apply than on the left side click on Module Option and select Module SDK's options and select Project SDK 11. and at the bottom at Project Settings CLICK on SDK and select on 11 SDK versions. It will give you the JDK path
C:\Program Files\Android\Android Studio\jbr
Copy this path and Open the System Environment Variable Create a New JAVA_HOME path with the location
and click OK and save everything Now run your app in ANDROID STUDIO and ENJOY!
Context: Flutter, Mac M1, Java 19.0.2
Problem occured on following command:
flutter build apk
I just installed (reintalled) gradle via homebrew like this:
brew install gradle
I suppose it was related to my recent upgrade (Java was upgraded to OpenJDK Temurin 19.0.2).
I also noticed that flutter command was trying to use gradle 7.4 (the only one gradle version installed before). As previously mentioned by others, there has to be consistency between your Java version and gradle version according to Gradle Official Compatibility Matrix.
Please, verify it with following commands:
java -version
gradle -version
I think this process / solution can be applicable in general. Hope it helps!

Adding JRE 7 to eclipse on mac osx after upgrading to app-engine 1.7.7

I have been developing an app with the GAE-Eclipse-plugin. I just updated eclipse to app-engine 1.7.7. So that launched a whirlwind of errors that I have been walking thru. I finally figured that I need to install jre7. So I went to http://www.macupdate.com/app/mac/44788/java-se-runtime-environment-7 and installed the jre. Then I try to link eclipse to the jre by going thru eclipse > preferences > java > installed JREs. There I only saw Java SE 6. So I clicked on MacOS X VM then browsed to /System/Library/Frameworks/JavaVM.framework/Versions/. When I got there I expected to find 1.7. But instead, after 1.6.0 I see A, Current, CurrentJDK.
Is the correct version missing from the list or which one of those three am I to select otherwise?
You are installing the Java SE Runtime Environment (JRE), which just updates the browser plugin (/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java). You want to install the Java Development Kit (JDK). I always go to Oracle directly, but here's the MacUpdate link.
Once it's installed you should see it under /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk. Eclipse should see it, but if you want to use it by default you will need to either update your java links in /usr/bin (not recommended) or update your eclipse.ini file (${eclipse.home}/Eclipse.app/Contents/MacOS/eclipse.ini) to point to the new JVM.

Installing ADT plugin 16.0.1 on Eclipse Indigo- windows

When I try to install the ADT 16.0.1 plugin on Eclipse Indigo java developer edition release 1 or Helios normal edition release 2, I get the following error:
Cannot complete the install because one or more required items could not be found.
Software currently installed: Shared profile 1.0.0.1316138460759(SharedProfile_epp.package.java 1.0.0.1316138460759)
Missing requirement: Shared profile 1.0.0.1316138460759 (SharedProfile_epp.package.java 1.0.0.1316138460759) requires 'org.maven.ide.eclipse [1.0.100.20110804-1717]' but it could not be found
I've tried to lookup the package it's refering to on apache, JDK reference and android developer reference but no luck!
This's not my first time installing ADT, I already have it installed on Ubuntu and it works. I also had the old release (ADT 15) installed on Eclipse galileo on windows, but I re-installed windows (i'm running windows 7 ultimate by the way) and I can run the old release but it's very good developing with ICS API-s.
So, if anyone could help, it would be highly appreciated.
Lots of people have this type of problem with many different required items missing.
The last time I had this problem it was fixed by going to Window->Preferences
Then selecting Install/Update->Available Software Sites
Make sure everything listed is checked
In my installation I have:
https://dl-ssl.google.com/android/eclipse/
http://download.eclipse.org/releases/indigo
http://download.eclipse.org/eclipse/updates/3.7
You may also need to run Eclipse as an administrator
I was able to install the ADT Plugin only after
I moved the eclipse folder to a location without spaces (e.g.: c:\development\android\eclipse
I ran the Eclipse Update procedure as administrator
Also I am using the 32bit version even though I use windows7 64bit.
you just need to run as administrator
run Eclipse with compatibility mode winXP pack 2 and Run as Administrator.
You can find it by Right clicking Eclipse.exe > Properties > Compatibility Tab

How to run Eclipse Indigo on JDK 1.7 OSX

With the recently OSX JDK 7 ea release from Oracle. How to run Eclipse Indigo ?
I get the following error msg:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home
$ java -version
openjdk version "1.7.0-ea"
OpenJDK Runtime Environment (build 1.7.0-ea-b211)
OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)
$ /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
JavaVM: requested Java version ((null)) not available. Using Java at "" instead.
JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.
I just tried this myself and had some complications so I thought I would share what ended up working for me:
Download and install Mac OSX version of Java SE Development Kit 7
Under Eclipse -> Preferences -> Java -> Installed JREs, click Add, select Mac OS X VM, then click Next.
Enter "/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home" as the JRE home directory, enter something reasonable like "Java SE 7" as the JRE name, and then click Finish. (Note that you won't be able to navigate to the "../Contents/Home" folder. You will have to type it in manually.)
After adding the new JRE to the list of Eclipse installed JREs, check the box next to the new JRE that you just added and then click OK.
Now under Eclipse -> Preferences -> Java -> Compiler, select 1.7 from the "Compiler compliance level" dropdown and click Ok.
Hope this helps someone who has problems figuring this out. The confusing part for me was selecting the JRE home directory in Eclipse, since I wasn't able to navigate to it.
The Eclipse bug is resolve in the last Eclipse 3.8 Milestone.
It's work for me.
Try this: http://twitter.com/#!/cimnine/status/126219234203271168/photo/1
Worked for me.
This is an old solution and has no relevance anymore.

How do I use JDK 7 on Mac OSX?

I would like to use the WatchService API as mentioned in this link:
http://download.oracle.com/javase/tutorial/essential/io/notification.html
After reading around, I found out that WatchService is part of the NIO class which is scheduled for JDK 7. So, it is in beta form. It's fine.
http://jdk7.java.net/download.html has the JDK which I downloaded and extracted. I got a bunch of folders. I don't know what to do with them.
Then, I read around some more and found that some nice group of people created JDK 7 as a binary so someone like me can install it easily. It is called Open JDK:
http://code.google.com/p/openjdk-osx-build/
So, I downloaded the .dmg file and install it. Then I open "Java Preference" and see that OpenJDK7 is available.
So, now I feel that I can start trying out WatchService API. From the tutorial in the first link, the author gave a .java file to test it out first and make sure that it is running. Here is the link to the file:
http://download.oracle.com/javase/tutorial/essential/io/examples/WatchDir.java
So, I boot up Eclipse (actually I use STS) and create a new Java project and choose JaveSE-1.7 in the "use an execution environment JRE:". Under the src folder, I copy pasted the WatchDir.java file.
And I still see tons of squiggly red lines. All the "import.java.nio.*" are all red and I cannot run it as a Java app.
What do I need to do?
This is how I got 1.7 to work with Eclipse. I hope it helps.
I Downloaded the latest OpenJDK 1.7 universal (32/64 bits) JDK
from Mac OS/X branch from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
copied the jdk to /Library/Java/JavaVirtualMachines/ next to the
default 1.6.0 one
In Eclipse > Preferences > Java > Installed JREs you add a new one, of type MacOS X VM, and set the home as /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home and
name Java SE 7 (OpenJDK)
Click Finish
Set the added JRE as default
that should be it :)
Oracle has released JDK 7 for OS X.
Java 9, 10, 11
Years ago, Apple joined the OpenJDK project, transferring their formerly proprietary macOS-specific JVM code as free-of-cost open-source. Apple ceased distribution of their own branded JVM/JDK, relying on Oracle’s branded releases to include a version for macOS.
Oracle has recently announced their intention to bring their Oracle-branded JVM release to feature parity with the OpenJDK project, with virtually the same code base. The company even donated their previously commercial tools, Flight Recorder & Mission Control, to the OpenJDK project. This is part of the shift to a new rapid “release train” plan for predictably scheduled versioning of Java and OpenJDK. Notably, the periods for free-of-cost public updates is now shortened. See this 2017-09 announcement and this posting by Mark Reinhold.
As a result of all this, macOS users of Java have a choice of vendors for a Java implementation. At this point, at least three sources are based on OpenJDK for macOS:
Oracle releases of the JDK and JRE, with optional paid support.
Azul Systems releasing:
Zulu line of free-of-cost JVMs with optional paid support.
Zing line of commercial JVMs with special features such as an alternate garbage-collector.
OpenJDK source code, roll-your-own compilation & installation (perhaps not practical for most of us).
Meanwhile, IBM donated code for a JVM to the Eclipse Foundation, now housed in the OpenJ9 project. I wonder if they might support a macOS release as well, though it is too soon to tell.
Personally, I am currently using the Zulu release of Java 10.0.1 from Azul on macOS High Sierra successfully with IntelliJ 2018.2 to produce Java-backed web apps with Vaadin.
Installation/Removal
Both Oracle and Azul provide utterly easy-to-use installers to install the JVM/JDK on your Mac. Verify your installation by using the Terminal.app (or equivalent) to type and run:
java -version
You will find the Java installations in this folder at the root level of your drive (not in your home folder):
/Library/Java/JavaVirtualMachines
Each version from each vendor is found there, in a labeled nested folder. You can delete any installation simply by deleting the nested folder for that version and providing your system password when prompted.
Java 8
You can download the Java Development Kit (JDK) for Java 8 for the supported versions of Mac OS X:
Mountain Lion (10.8.3+)
Mavericks (10.9)
Yosemite (10.10)
El Capitan (10.11)
Each version of JVM you install can be found here:
/Library/Java/JavaVirtualMachines
For more instructions and FAQ, see this Oracle Guide.
Java 7
For every release of Java 7 since Update 4, a Mac version has been ready alongside the other platforms. Runs on Macs with 64-bit hardware on Lion (10.7.3+), Mountain Lion (10.8.3+), and Mavericks (10.9.x).
Oracle announced the official release of the JDK for Java SE 7 Update 4 on Mac OS X (Lion), as of 2012-04-26. No more need for the tricks discussed on this page.
Installation is simple per these instructions:
Download from the usual place on the Oracle web site.
Mount the DMG.
Run the installer.
This release has a few limitations, most notably the lack of support for Java Web Start and the Java Plugin for web browsers. That support is expected later this year.
After installing, read the JDK for Mac ReadMe. Most importantly, if you want Java 7 to be the default, drag it to the top of the list in the Java Preferences app found in your Utilities folder.
Mac OS X easily supports multiple JVMs simultaneously. Each is now found here:
/Library/Java/JavaVirtualMachines
Congratulations to the Apple & Oracle teams for their achievement. This geek gets a thrill seeing Mac OS X listed as a "Certified System Configuration".
Tip: To start Eclipse on a Mac with only Java 7 installed, open the alias file named eclipse rather than the file named Eclipse.app.
Java 6
Apple continues to supply an up-to-date implementation of Java 6 for all versions of Mac OS X up through Mountain Lion.
If you do something that requires Java, such as type "java -version" in Terminal.app, a dialog appears offering to install Java for you. If you accept, installation happens automatically similar to other "Software Updates" from Apple.
You will find Java installed in this location, different than Java 7 & 8:
/System/Library/Java/JavaVirtualMachines
Java 6 has reached end-of-life with Oracle as of 2013-02 (unless you have a commercial support agreement with Oracle). So you should be moving to Java 7 or 8.
Testing New Version
In Terminal.app, type java -version to verify which version is the current default.
Deleting Old Versions
After installing a fresh version, you may want to visit the folder described above to delete old versions. Move the folder to the Trash, and provide your System password complete the move.
By the way, Apple provides a mailing list for developers’ technical issues related to Java on OS X.
An easy way to install Java 7 on a Mac is by using Homebrew, thanks to the Homebrew Cask plugin (which is now installed by default).
Run this command to install Java 7:
brew cask install caskroom/versions/java7
Get cask
brew tap caskroom/cask
Install java7:
brew tap caskroom/versions
brew cask install java7
(I had difficulty finding the download link of java7 on oracle website, as they're just "recommending" java8 )
EDIT January 2018 (As pointed by Ankur):
Use zulu7 cask. Zulu is a certified build of OpenJDK produced by Azul Systems that should be around for a long time (they even offer JDK6 builds still).
brew cask install caskroom/versions/zulu7
I know that some may want to smack me for re-opening old post, but if you feel so do it I just hope this may help someone else trying to set JDK 7 on Mac OS (using IntelliJ).
What I did to get this working on my machine is to:
followed instructions on Oracle JDK7 Mac OS X Port for general installation
in IntelliJ open/create new project so you can add new SDK (File > Project Structure)
select Platform Settings > SDKs, press "+" (plus) sign to add new SDK
select JSDK and navigate to /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home. Do not get it mistaken with /Users/YOUR_USERNAME/Library/Java/. This will link 4 JARs from "lib" directory (dt.jar, jconsole.jar, sa-jdi.jar and tools.jar)
you will need also add JARs from /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/jre/lib (charsets.jar, jce.jar, JObjC.jar, jsse.jar, management-agent.jar, resources.jar and rt.jar)
after installing the 1.7jdk from oracle, i changed my bash scripts to add:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home
and then running java -version showed the right version.
It's possible that you still need to add the JDK into Eclipse (STS). Just because the JDK is on the system doesn't mean Eclipse knows where to find it.
Go to
Preferences > Java > Installed JREs
If there is not an entry for the 1.7 JDK, add it. You'll have to point Eclipse to where you installed your 1.7 JDK.
If Eclipse can't find a JRE that is 1.7 compatible, I'm guessing that it just uses your default JRE, and that's probably still pointing at Java 1.6, which would be causing your red squiggly lines.
I needed to adapt #abe312's answer since there has been some changes with brew lately.
I installed zulu7 and setup JAVA_HOME by running:
brew install --cask homebrew/cask-versions/zulu7
echo "export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-7.jdk/Contents/Home" >> ~/.zshrc
I had to enter my password for installing zulu7. You may need to modify the last command if you are using a different shell.
How about Netbeans, here is an article how to set it up with NB7:
http://netbeanside61.blogspot.com/2011/06/downloading-openjdk7-binary-for-mac-os.html
Maybe similar steps for Eclipse.
As of April 27th there is an offical Oracle release of Java SE 7u4. Download the disk image and run the installer - then see the Mac readme.
As of December 2017, previously posted links don't work, but JDK 7 can still be downloaded from Oracle Archives (login required):
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
The instructions by peter_budo worked perfectly. I had to add the jars under /Library/Java/JavaVirtualMachines/JDK 1.7.0 Developer Preview.jdk/Contents/Home/jre/lib/ to my IntelliJ project libraries. Now it works like a charm. Note that I didn't need my IDE itself to run under 1.7; rather, I only needed to be able to compile and run against 1.7. I'll most likely continue to use Apple's JRE for running the IDE since it's probably more stable with respect to graphics routines (Swing, AWT). Like the OP, I was really keen on testing out the new NIO2 API. Looking good so far. Thanks, Peter.
What worked for me on Lion was installing the JDK7_u17 from Oracle, then editing ~/.bash_profile to include:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home
Now, Use command
Update 2020: 04
To install Java7 with homebrew run:
brew tap homebrew/cask-versions
brew cask install java7
Hope this help.
I updated to Yosemite and Android Studio wouldn't clean my projects or Run them on virtual or real device because of the following error:
Failed to complete Gradle execution.Cause:Supplied javaHome is not a valid folder. You supplied: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
After some research and trouble shooting, I found that the JDK file that was being pointed to at "/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home" wasn't there; all of "JavaVirtualMachines/1.6.0.jdk/Contents/Home" was missing from "/System/Library/Java". So, I copied "JavaVirtualMachines/1.6.0.jdk/Contents/Home" over from "/Library/Java/" to "/System/Library/Java/" and cha ching! I was back in business.

Resources