Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install JDK 8 on OS X Mountain Lion with the new lambda features

Tags:

macos

java-8

Can anybody help me with installing JDK 8 on mac Mountain?

I have installed java_for_os_x_2013002_dp__11m4203.dmg and I can see: /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home . But don't know what more to do.

How can I make a symlink to the new version and so on?

I use Eclipse and maven so I don't want any conflict with them. I'm a new mac user.

JDK 7 is already installed on my mac but I just want do some experiment with the new lambda expression.

Thanks for all help

like image 665
user1067665 Avatar asked Mar 24 '13 08:03

user1067665


2 Answers

Though EKG's answer explains well what you need to do to run a Java 8 project, if you wish to set Java 8 to be your default version on the system you can set it as the Java home.

I had (earlier for maven) added the following line to my .profile to set my Java home.

export JAVA_HOME=$(/usr/libexec/java_home)

Now, to set it to a specific version, I updated it to the following value

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

This does allow you to set a specific version as your default though how to update the default for the entire system (every user who hasn't set one themselves) still eludes me.

Note: I'm aware this isn't a direct answer but is something which people will come to when looking for this. Alas, this is too big to write in a comment. If this "answer" is better represented in another way, I'd be happy to make changes.

like image 107
javatarz Avatar answered Oct 30 '22 15:10

javatarz


If you just want to try coding with JDK8, you dont need to install it on your system. Just as a JRE in a version of eclipse with Java 8 support. To get a beta build of eclipse you can either build it yourself (I had issues with this) or download a pre-built version. I couldn't find any pre-built versions on the eclipse site, but I found one here. http://downloads.efxclipse.org/eclipse-java8/

Once You have that downloaded, go to Eclipse > Preferences > Java > Installed JREs Click Add, and specify the java 8 home directory. For me this was /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home.

Now create a project. The source level of 1.8 is not available in the UI, you need to modify the <my_project>/.settings/org.eclipse.jdt.core.prefs and make sure you have the lines below.

org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.source=1.8

Then you're good to go.

The build of eclipse is beta, so code assist doesn't always work with the new syntax. But it compiles and runs java 8 code fine :-)

like image 3
ekj Avatar answered Oct 30 '22 15:10

ekj