Programming Java 8 in Eclipse
Asked Answered
D

4

22

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.
Dail answered 8/11, 2012 at 18:21 Comment(3)
Step 3. What do you mean you imported the checked out projects in an instance of Eclipse ? What folder did you put them in? Plugins, features, configuration? What did you do here? Thanks!Quinonoid
Eclipse provides a feature for importing an existing project into a workspace. Are you familiar with this feature?Dail
this works for me: oracle.com/technetwork/articles/java/lambda-1984522.htmlDavena
C
16

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

Columbous answered 8/11, 2012 at 19:34 Comment(6)
Yes. That's exactly what I ended up doing, too. The UI didn't allow me to set the compliance level to 1.8. So, I edited org.eclipse.jdt.core.prefs manually.Dail
It's confusing that the wiki at wiki.eclipse.org/JDT_Core/Java8#What_to_do_to_set_up_the_IDE instructs the user to install EE JavaSE-1.8.Dail
The wiki does not actually say that the user has to 'install' EE JavaSE 1.8. It just says that the EE is used :-)Columbous
In any case, I see that Stephan just updated the wiki page with what I just answered here.Columbous
What is the file path to the preference file, i can't seem to find it.Distasteful
Ctrl+Shift+R (Open Resource) is your friend.Columbous
C
29

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.

Conversation answered 2/4, 2014 at 19:51 Comment(1)
There is no menu called Help > Eclipse Marketplace , in Eclipse 4.2John
C
16

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

Columbous answered 8/11, 2012 at 19:34 Comment(6)
Yes. That's exactly what I ended up doing, too. The UI didn't allow me to set the compliance level to 1.8. So, I edited org.eclipse.jdt.core.prefs manually.Dail
It's confusing that the wiki at wiki.eclipse.org/JDT_Core/Java8#What_to_do_to_set_up_the_IDE instructs the user to install EE JavaSE-1.8.Dail
The wiki does not actually say that the user has to 'install' EE JavaSE 1.8. It just says that the EE is used :-)Columbous
In any case, I see that Stephan just updated the wiki page with what I just answered here.Columbous
What is the file path to the preference file, i can't seem to find it.Distasteful
Ctrl+Shift+R (Open Resource) is your friend.Columbous
P
7

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.

Preheat answered 7/4, 2014 at 13:11 Comment(1)
Thanks!! This was the easiest way to do it. Got it working in 30 seconds :D :DJoann
T
-1

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

Thomasson answered 13/5, 2015 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.