简体   繁体   English

如何使用新的lambda功能在OS X Mountain Lion上安装JDK 8

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

Can anybody help me with installing JDK 8 on mac Mountain? 任何人都可以帮我在mac Mountain上安装JDK 8吗?

I have installed java_for_os_x_2013002_dp__11m4203.dmg and I can see: /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home . 我已经安装了java_for_os_x_2013002_dp__11m4203.dmg ,我可以看到: /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. 我使用Eclipsemaven所以我不希望与它们发生任何冲突。 I'm a new mac user. 我是一个新的mac用户。

JDK 7 is already installed on my mac but I just want do some experiment with the new lambda expression. JDK 7已经安装在我的mac上,但我只是想用新的lambda表达式做一些实验。

Thanks for all help 谢谢你的帮助

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. 虽然EKG的答案很好地解释了运行Java 8项目需要做什么,但如果您希望将Java 8设置为系统上的默认版本,则可以将其设置为Java主目录。

I had (earlier for maven) added the following line to my .profile to set my Java home. 我(之前为maven)将以下行添加到我的.profile中以设置我的Java主页。

export JAVA_HOME=$(/usr/libexec/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) 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. 如果以另一种方式更好地表达这个“答案”,我会很乐意做出改变。

If you just want to try coding with JDK8, you dont need to install it on your system. 如果您只想尝试使用JDK8进行编码,则无需在系统上安装它。 Just as a JRE in a version of eclipse with Java 8 support. 就像在Java 8支持的eclipse版本中的JRE一样。 To get a beta build of eclipse you can either build it yourself (I had issues with this) or download a pre-built version. 要获得eclipse的beta版本,您可以自己构建它(我遇到此问题)或下载预构建的版本。 I couldn't find any pre-built versions on the eclipse site, but I found one here. 我在eclipse网站上找不到任何预先构建的版本,但我在这里找到了一个版本。 http://downloads.efxclipse.org/eclipse-java8/ 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. 下载完成后,转到Eclipse> Preferences> Java> Installed JREs单击Add,然后指定java 8主目录。 For me this was /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home. 对我来说这是/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. UI的源级别1.8不可用,您需要修改<my_project>/.settings/org.eclipse.jdt.core.prefs并确保您拥有以下行。

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. eclipse的构建是beta版,因此代码辅助并不总是适用于新语法。 But it compiles and runs java 8 code fine :-) 但它编译并运行java 8代码罚款:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM