askvity

How do I change workspace compliance in Eclipse?

Published in Eclipse IDE 3 mins read

You can change the workspace compiler compliance level in Eclipse through the preferences settings. Here's how:

  1. Open Preferences: From the Eclipse menu bar, select Window > Preferences.
  2. Navigate to Compiler Settings: In the Preferences dialog, navigate to Java > Compiler.
  3. Set Compiler Compliance Level: Locate the "Compiler compliance level" setting. Use the dropdown menu to select your desired compliance level (e.g., 1.8, 11, 17, etc.).
  4. Apply and Close: Click Apply and then OK to save the changes. Eclipse might prompt you to rebuild your project after changing the compliance level.

Explanation:

The compiler compliance level determines the Java language version your code is compiled against. Changing it allows you to use features from different Java versions, and it also affects the validation rules enforced by the compiler. For example, if you set the compliance level to 1.8, you can use Java 8 features like lambda expressions and streams. If you set it to 11, you can use Java 11 features, and so on.

Project-Specific Compliance:

The workspace compliance level acts as the default for all projects in your workspace. However, you can override this setting for individual projects. Here's how:

  1. Open Project Properties: Right-click on the project in the Project Explorer view and select Properties.
  2. Navigate to Java Compiler: In the Properties dialog, navigate to Java Compiler.
  3. Enable Project-Specific Settings: Check the box labeled "Enable project specific settings".
  4. Set Compliance Level: Adjust the "Compiler compliance level" setting to the desired value for this specific project.
  5. Apply and Close: Click Apply and then OK to save the changes.

Example Scenario:

Let's say your workspace compliance is set to 1.8. You have a legacy project that needs to be compiled using Java 7. You would then modify the properties of that specific project to use compliance level 1.7.

Important Considerations:

  • Make sure the Java Development Kit (JDK) installed on your system supports the compliance level you choose.
  • Changing the compliance level might require you to update your code to align with the selected Java version or resolve compatibility issues.
  • If your project relies on external libraries, ensure those libraries are compatible with the chosen compliance level.

Related Articles