Sunday, 21 February 2016

Adding Java 8 support to Eclipse kepler

Background

In last post we saw how to use Lambda expressions (well at an introductory level). It is equally important to run it in an IDE like Eclipse to start with. Hence in this post we will see how to compile and run Java 8 compatible code in your Eclipse. Eclipse has a JRE which it uses to compile and run the code and there is compiler compliance level  which basically recognizes your syntax. For example something like below - 

List<String> myList = new ArrayList<>();

won't work with compliance level 6 as the diamond structure was introduced in Java 7. So compliance level 7 is required. We will come to all of this in a moment. This is just a background to get you started. My Eclipse version is Kepler (After upgrading from Juno)- 




NOTE : Eclipse Kepler SR2 & Eclipse Luna are the versions that will support Java 8. Older versions will not (And by not I mean you will see compiler warnings, you can still compile and run if you have Java8 JRE). So of you are using older versions please consider upgrading.

Getting Started

First lets take care of Java compiler compliance level. For that go to Help -> Install new Software



Next add following URL to it and press enter -
  • http://download.eclipse.org/eclipse/updates/4.3-P-builds/
Then select Eclipse java 8 support (for Kepler)



Click Next.Accept TnC and click Finish. Next select 1.8 as compiler compliance level.



You will also need to add JRE 8 as your java runtime (Windows -> Preference -> Installed JREs).



NOTE : Juna 4.4 SR2 already has that. So you can directly download it to save all this migration trouble.

Related Links

No comments:

Post a Comment

t> UA-39527780-1 back to top