HOWTO · Java

How to Change Java Version in Eclipse

This article teaches us to change the Java version for the current project in Eclipse.

On this page

To change the Java version used by an Eclipse project, first install the desired Java Development Kit (JDK) or Java Runtime Environment (JRE) on your computer, then make that installation available to Eclipse and select it for the project. Eclipse does not download or install Java through its runtime preferences. A new project and an existing project each need their own runtime selection, and this selection is separate from the Java compiler compliance level.

Add an Installed JRE to Eclipse

Eclipse can select a Java runtime that is already present on the computer. Before changing a project, install the JDK or JRE version you intend to use. A JDK includes development tools as well as the runtime; it is generally the suitable choice when compiling Java source code. A JRE supplies the runtime environment. The installation package and supported Java releases depend on your operating system and project requirements.

Register the local installation in Eclipse’s Java runtime configuration by identifying its installation location and giving it a recognizable name. The exact preference labels and navigation can differ between Eclipse releases, so use the Java runtime configuration available in your installed version rather than relying on a particular menu sequence. Registration tells Eclipse where Java is installed; it does not install Java or make that runtime the choice for every project automatically.

If the desired installation is already listed among Eclipse’s available runtimes, you can use that entry. Otherwise, install Java first, then add its local installation to Eclipse. Choose a clear name that includes the Java version or distribution when several installations are present. This makes the later project selection easier to identify and helps avoid confusing two runtimes with similar names.

Choose a Java Version for a New Project in Eclipse

When creating a project, choose one of the registered runtimes as the project’s JRE. This selection determines which Java runtime Eclipse associates with that project when it launches or builds the project using that configuration. Select the version required by the application and its dependencies; using a newer Java installation does not by itself guarantee compatibility with an application that targets an older release.

If the intended runtime is not offered during project setup, return to Eclipse’s registered runtimes and confirm that the local JDK or JRE has been added. Then select the project runtime again. The project may also have a separate compiler compliance or source compatibility setting. That setting controls which Java language and class-file level the compiler targets; selecting a runtime does not necessarily change it. Align both settings with the project’s requirements, but do not assume they are the same option.

Change the Java Version for an Existing Project in Eclipse

For an existing project, change the runtime associated with that project to the registered JDK or JRE you want to use. Eclipse exposes project configuration for this purpose, though the names and arrangement of controls vary by release. Find the project’s Java runtime or JRE System Library setting, replace its current runtime selection, and apply the change using the controls in your Eclipse version. If the desired runtime is absent from the available choices, register its local installation first.

After applying the change, inspect the project’s runtime setting and confirm that it names the intended installation. You can also run the project and check the Java version reported by the application. For a simple check inside the project, this complete Java program prints the runtime version of the JVM that runs it. In the recorded run for this example, the program printed 17.0.20.1; that value identifies the JVM used for that run, and your output will reflect the JVM selected for your project.

Run this example:

public class Main {
    public static void main(String[] args) {
        System.out.println(System.getProperty("java.version"));
    }
}
17.0.20.1

A successful launch confirms which JVM ran that program; it does not establish the compiler’s source or compliance level. If the runtime report differs from the version you intended, revisit the project’s runtime selection and check which launch configuration or project is being run. For a complete migration, review the compiler compatibility setting separately and make sure required libraries and build tools support the selected Java release.