Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have Eclipse use JDK8 to compile a project?

I'm experimenting with the new jdk8 what is available here http://jdk8.java.net/lambda/

I'm able to compile and run my project from command line.

I'm also able to add this new JDK to Installed JREs in Eclipse. However, I'm not able to have Eclipse to compile and run the project with this JDK.

I'm trying to change the settings on Project Properties/Java Compiler but the Use [JDK] compliance from execution environment on the 'Java Build Path' checkbox is disabled and no matter whatever I click on this page, I cannot make it work.

I have Eclipse Platform Version: 3.7.1

Any ideas?

thx

like image 524
bpgergo Avatar asked Nov 14 '11 14:11

bpgergo


People also ask

How do I change the Compiler in Eclipse?

To change the compiler version in eclipse you need to go to Windows > Preferences > Java > Compiler. There you will see Compiler Compilation Level where in drop-down you will see all compiler version available in system.

How do I compile a project in Eclipse?

Step 1: Open Eclipse and click File > New > Java Project. Step 2: Provide the Project Name and click on the Finish button. Step 3: In the Package Explorer (left-hand side of the window) select the project which you have created. Step 4: Right-click on the src folder, select New > Class from the submenu.

How do I change my Java from 11 to 8 in Eclipse?

In eclipse go to Window -> Preferences -> Java -> Compiler , there you can change the java versions.


2 Answers

Eclipse uses a built-in compiler rather than javac. The built-in compiler obviously doesn't support Java 8 yet.

You can define a custom builder for your project which will call your javac. In the project's preferences, go to "Builders", add a new custom builder (which can be either an Ant script or an executable program) and disable the default built-in Java builder.

Afterwards, running the project with the JDK of your choice shouldn't be a problem - adding it to the "Installed JREs" preference page (as you did) should be sufficient.

like image 89
Eli Acherkan Avatar answered Oct 11 '22 02:10

Eli Acherkan


Eclipse now supports JDK 8 EA:

The Eclipse JDT/Core team is pleased to announce the availability of early access builds with support enabled for the following Java 8 features.

We recommend that you start with a clean install of

  • Either 4.3.1 or 4.4 M2 SDK
  • Update the JDT/Core, JDT/UI bundles from http://dist.springsource.com/snapshot/TOOLS/java8/e43

This update site is set up to periodically rebuild and package the relevant projects from the top of the BETA_JAVA8 development branch.

Source: http://dev.eclipse.org/mhonarc/lists/eclipse-dev/msg09679.html


EDIT:

After upgrading eclipse, you need to change the JDK and the compiler level. Here is a screenshot of using lambda within Eclipse:

enter image description here

like image 20
Eng.Fouad Avatar answered Oct 11 '22 04:10

Eng.Fouad