Category: HowTo

Eclipse and Java 8 for early birds

There are still about five and a half months to wait for the General Availability (GA) of Java 8. It is announced for 18th March of 2014. For all that cannot wait until to test the new features with an IDE: this post describes how you can do it with the most recent version of Eclipse Luna.

In order to try out Eclipse with Java 8 you will have to

  • download and install JDK 8
  • clone Eclipse repository
  • build Eclipse
  • configure Eclipse

The Steps

Before you start please check if your system fulfills all necessary prerequisites. Depending on your system hardware and internet bandwidth the execution of the build script can take quite a long time (~8 hours in the author’s case).

  1. Download the Early Access (EA) distribution of JDK 8.
  2. Unpack the JDK archive file to an arbitrary directory.
  3. Create a directory for the build and export its file system path to a system variable named ECLIPSE_BUILD_HOME.
  4. Create an executable build script file with the following content:
  5. Execute the build script. Wait and be patient…
  6. Unless the build script execution failed the Eclipse distribution should be available at $ECLIPSE_BUILD_HOME/eclipse.platform.releng.aggregator/eclipse.platform.releng.tychoeclipsebuilder/sdk/target/products/org.eclipse.sdk.ide/linux/gtk. Choose the distribution appropriate to your OS’ architecture and copy it to a directory of your choice.
  7. Start Eclipse and specify a workspace directory.
  8. Add JDK 8 to the Installed JREs (Window - Preferences - Java - Installed JREs - Add...) and set it as default JRE.
  9. Create a Java project and add the following class to the default package: You should see a compile error saying: ‘Lambda expressions are allowed only at source level 1.8 or above’.
  10. Outside Eclipse, open the file org.eclipse.jdt.core.prefs contained in the Java project’s .settings directory. Change the values of the org.eclipse.jdt.core.compiler.compliance and org.eclipse.jdt.core.compiler.source settings to ‘1.8’.
  11. Within Eclipse, refresh and recompile the Java project. Now the compile error should have disappeared.
  12. Run the Java project and verify the console output. It should print out ‘Hello Java 8!’.
  13. Enjoy 🙂

Author’s System Environment

Please regard that this is just a listing of the author’s system environment under which the build succeeded. However, the Eclipse Wiki manages build instructions for other system environments, too.

  • Linux Mint Lisa KDE
  • Git 1.7.5.4
  • Java JDK 1.7.0_40 64-Bit
  • Java running in ‘Server’ mode (see http://wiki.eclipse.org/Platform-releng/Platform_Build#Java_Server_Mode)
  • JAVA_HOME variable set to home directory of Java
  • Apache Maven 3.0.5
  • MAVEN_HOME variable set to home directory of Maven
  • Default Maven settings (i.e. untouched ~/.m2/settings.xml)
  • ~22 GB of free HDD space

References