How to Configure JDK in Eclipse or STS Core Java IDE java by devs5003 - January 17, 2025January 17, 20250 How to Configure JDK in Eclipse or STS ? Configuring the Java Development Kit (JDK) in Eclipse or Spring Tool Suite (STS) is a crucial step for any Java developer. Whether you are a beginner or intermediate in java development, you might face some issue in configuring JDK in your IDE such as Eclipse or STS. This guide provides a detailed step-by-step process for configuring JDK in Eclipse or STS, along with common errors and their solutions. Table of Contents Toggle PrerequisitesStep-by-Step Guide: How to Configure JDK in Eclipse or STSStep#1. Verify JDK InstallationStep#2. Configure the JDK in Eclipse or STSStep (A): Open Eclipse/STS PreferencesStep (B): Add the Installed JDKStep (C): Set the Default JDKStep (D): Update Compliance LevelStep (E): Create a ProjectStep (F): Configure the JDK for ProjectsCommon Errors and Solutions Prerequisites Before proceeding with JDK configuration, make sure that you have the following in your system: JDK Installation: Download and install the latest version of the JDK from Oracle’s official website or OpenJDK if you don’t have it already. Eclipse or STS Installation: Download and install the latest version of Eclipse IDE or Spring Tool Suite from their respective official websites. Step-by-Step Guide: How to Configure JDK in Eclipse or STS Step#1. Verify JDK Installation Open a terminal or command prompt. Run the following commands to verify the installation: java -version Ensure the output displays the installed JDK version correctly. Step#2. Configure the JDK in Eclipse or STS Step (A): Open Eclipse/STS Preferences Launch Eclipse or STS. Navigate to Window > Preferences (on macOS, go to Eclipse > Preferences). Step (B): Add the Installed JDK In the Preferences window, expand Java and select Installed JREs. Click Add to add a new JDK. Select Standard VM and click Next. In the JRE Home field, browse to the JDK installation directory. Add path up to jdk folder. For example: For Windows: C:\Program Files\Java\jdk-21 For macOS: /Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home For Linux: /usr/lib/jvm/java-21-openjdk In the JRE Name field, add a name of your choice such as ‘jre-21’. We can also name it ‘JDK-21’ for better understanding. Eclipse will automatically detect the rt.jar or module files and display the list of JDK libraries. Click Finish. Step (C): Set the Default JDK Back in the Installed JREs section, select the newly added JDK. Click Apply and Close to save the settings. Step (D): Update Compliance Level Go to Window > Preferences. Navigate to Java > Compiler. In the Compiler compliance level dropdown, select required version eg. 21. Click Apply and Close. Step (E): Create a Project Create a New Project: Go to File > New > Java Project. Enter a project name and click Next. Configure the JRE: Under JRE, select Use an execution environment JRE and choose JavaSE-21. Finish Project Setup: Click Finish to create the project. Step (F): Configure the JDK for Projects Right-click your project in the Project Explorer. Select Properties > Java Build Path. Go to the Libraries tab, click Modulepath or Classpath, and select Add Library. Choose JRE System Library, click Next, and select Workspace default JRE (JDK 21). Click Finish, then Apply and Close. Common Errors and Solutions Error: Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available Cause: The JDK path is not configured or incorrectly set in Eclipse. Solution: Verify the JDK installation directory and ensure it is correctly added under Window > Preferences > Java > Installed JREs. Error: Version of the JRE/JDK is not compatible Cause: The project’s JDK version does not match the configured JDK in Eclipse. Solution: Update the JDK version under Window > Preferences > Java > Installed JREs. Ensure the project’s JDK version matches the one set in Project Properties > Java Build Path. Workspace fails to recognize the configured JDK Cause: Workspace settings are not updated after adding a new JDK. Solution: Restart Eclipse after adding the JDK. Go to Window > Preferences > Java > Installed JREs, select the desired JDK, and click Apply and Close. Error: Compiler compliance level is incompatible Cause: The compiler compliance level does not match the configured JDK. Solution: Navigate to Window > Preferences > Java > Compiler. Set the Compiler compliance level to match your JDK version. Eclipse does not detect the JDK installed on the system Cause: The environment variables ‘JAVA_HOME’ and PATH are not correctly set. Solution: Add JAVA_HOME pointing to your JDK installation directory. Update the PATH variable to include the bin directory of the JDK. Error: JDK not visible in Installed JREs Cause: The path to the JDK is incorrectly configured. Solution: Click Add in Window > Preferences > Java > Installed JREs. Manually browse to the JDK installation directory and add it. Error: Eclipse cannot find tools.jar Cause: A JRE is being used instead of a JDK. Solution: Replace the JRE with the JDK under Installed JREs. Ensure the project references the correct JDK. Error: Invalid JRE Definition Cause: The selected JDK path is incorrect or incomplete. Solution: Remove the invalid JDK entry from the Installed JREs. Re-add the JDK with the correct installation path. Error: Class File Version Error Cause: The JDK version used to compile the project differs from the runtime JDK. Solution: Ensure the Java Compiler settings in Eclipse are set to the desired Java version: Go to Project Properties > Java Compiler. Set the Compiler compliance level to the desired JDK version. Rebuild the project. You may also go through: How to run your first Java Program in Windows 10+. Related