Programming Java 8 in Eclipse

丶灬走出姿态 提交于 2019-11-29 02:02:28

问题


The development of Eclipse support for Java 8 is ongoing in a branch (http://wiki.eclipse.org/JDT_Core/Java8).

To try out the current Eclipse support for Java 8, I did the following:

  1. I installed a build of JDK 8 (This step is optional).
  2. I checked out branch BETA_JAVA8 of git://git.eclipse.org/gitroot/jdt/eclipse.jdt.core.git.
  3. I imported the checked out projects in an instance of Eclipse Juno SR1 (Build ID: 20120920-0800).
  4. I ran a new instance of Eclipse from my running Eclipse.

To use the new syntax available in Java 8, Eclipse said that I have to set the compliance level of my code to 1.8. To set the compliance level, I have to set the execution environment to JavaSE-1.8. This execution environment was not available at Windows -> Preferences -> Java -> Installed JREs -> Execution Environments.

How can I set the execution environment to JavaSE-1.8?

The following summarizes some of my attempts to install the execution environment:

  1. I followed the wiki instructions looking for a description of JavaSE-1.8 at the update site http://download.eclipse.org/eclipse/updates/4.2. But, the definition of the execution environment wasn't there.
  2. I looked for the JavaSE-1.8 profile in the git repository of rt.equinox.framework, but, it wasn't there.

回答1:


Think you just have to change the 'settings' directly in the 'preference file' : org.eclipse.jdt.core.prefs .

e.g. org.eclipse.jdt.core.compiler.compliance=1.8




回答2:


I just went to the Eclipse Marketplace from inside of Eclipse (Help/Eclipse Marketplace...) and installed the "Java 8 support for Eclipse Kepler SR2", and the new "JavaSE-1.8" execution environment showed up automatically. I had previously installed Java 8 and added it as a 'Installed JREs' entry. No need to mess with property files.




回答3:


If you have Kepler you can get it using a patch that has installation instructions on this page:

https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler

Starting with I20140318-0830 all Luna (4.4) builds on our downloads page contain the Eclipse support for Java™ 8. For Kepler SR2 (4.3.2) a feature patch needs to be installed. This page describes how to do this.




回答4:


Eclipse version >=Luna (that's one after Kepler) runs smoothly with java 8.



来源:https://stackoverflow.com/questions/13295275/programming-java-8-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!