Saturday, July 30, 2011

Using Java 7 in Eclipse

1. Download Eclipse 3.7 Maintenance Build:
Eclipse 3.7 does not have support for Java 7, but the good news is that you can download a a 3.7 "maintenance build" (>= M20110729-1400) which does. I downloaded mine from here. The download was really slow, because it was coming from Canada and there were no other mirrors!

2. Add a Java 7 JRE:
Start Eclipse and go to Window > Preferences. Navigate to Java > Installed JREs and add your Java 7 JRE to the list, as the default JRE.

3. Upgrade Compiler Compliance Level:
Once again, in your preferences go to Java > Compiler and select 1.7 as the "Compiler compliance level".

4. Check Project JRE:
If you are working on an existing project, you need to make sure that the project is using JDK7 system library. Go into your project properties and into Java Build Path. Select the Libraries tab and check the version of your JRE System Library. If necessary, press Edit... to change it to JDK7.

5. Test it out:
Create a test class and use a Java 7 feature e.g. List<String> list = new ArrayList<>();. This should compile successfully. Eclipse should even be able to auto-complete the diamond.

The latest news on Eclipse Java 7 support can be found on the Eclipse wiki: http://wiki.eclipse.org/JDT/Eclipse_Java_7_Support_(BETA).

No comments:

Post a Comment