Java projects on the same Linux desktop can need different Java releases. Eclipse lets you register an installed Java Development Kit (JDK) and assign it to one project's build path while keeping the workspace default for other projects.

The JRE System Library supplies the Java platform classes Eclipse builds against. The project's compiler target still has to be compatible with the JDK, since a runtime cannot load class files compiled for a newer release.

A Java Application launch normally inherits its runtime from the project. A saved launch configuration can override that choice, and the executable in the Console header shows which runtime Eclipse actually launched.

Steps to configure a JDK in Eclipse:

Start in Eclipse with your Java project visible in Project Explorer and the Console view open. The project needs one runnable main method that prints output. The project's code needs to be compatible with the JDK release you plan to assign, and any saved launch configuration needs to inherit the project's JRE. Use a JDK already installed on your computer whose directory is absent from Installed JREs. The sample project java-version in ~/eclipse-workspace has a VersionCheck class that prints the java.version property.

If Eclipse opens a sponsor page in your browser, you can close it. If Install Java 27 Support appears, choose whether to install it or dismiss the notice. Begin with step 1 once the workbench is ready.

  1. Open the Window menu in Eclipse.
  2. Choose Preferences… from the menu.
  3. Enter Installed JREs in the Preferences filter field.
  4. Select Installed JREs under Java.
  5. Click Add… on the Installed JREs page.
  6. Click Next > with Standard VM selected.
  7. Click the JRE home field.
  8. Enter the root directory of your JDK, such as /opt/jdk-21, in JRE home.

    The root directory contains bin/java and bin/javac. If Finish stays unavailable because the name is already in use, replace the text in JRE name with a distinct name.

  9. Click Finish once it is enabled.
  10. Click Apply and Close with the original default still checked.
  11. Right-click your project in Project Explorer.
  12. Choose Properties.
  13. Select Java Build Path in the project properties.
  14. Open the Libraries tab.
  15. Double-click the existing JRE System Library entry.

    The entry can sit under Modulepath or Classpath.

  16. Select Alternate JRE.
  17. Open the Alternate JRE list.
  18. Select the JDK you just added, such as jdk-21.
  19. Click Finish in Edit Library.
  20. Click Apply and Close to save the project build path.
  21. Open the Run menu with your project selected.
  22. Hover over Run As.
  23. Choose Java Application.
  24. Click the Console tab.
  25. Verify the launch in Console by matching the java executable in the header to your chosen JDK and checking for your program's normal output without an error such as UnsupportedClassVersionError.

    The sample launch uses /opt/jdk-21/bin/java and prints 21.0.13.1.

Share this guide