IntelliJ IDEA
unsupported class file
major version 60
Java
troubleshooting

How can I fix unsupported class file major version 60 in IntelliJ IDEA?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

When working with Java projects in IntelliJ IDEA, you might encounter an error message that says "unsupported class file major version 60". This issue often arises due to a mismatch between the Java version you're compiling with and the version of the Java SDK that IntelliJ IDEA is configured to use. In this article, we'll explore why this happens, and how you can resolve the problem.

Understanding Java Class File Versions

Java class files are specific to the Java Virtual Machine (JVM) version they are compiled for. Each version of the Java language comes with a corresponding class file version. The compilation and runtime environments need to align with these versions to avoid compatibility issues.

Here's a quick overview of some major Java versions and their corresponding class file versions:

Java VersionClass File Major Version
Java 852
Java 953
Java 1054
Java 1155
Java 1256
Java 1357
Java 1458
Java 1559
Java 1660

The "unsupported class file major version 60" error typically occurs if you're trying to run Java 16 bytecode on a lower JVM version.

Resolving the Issue

Here are steps you can take to resolve the "unsupported class file major version 60" error in IntelliJ IDEA:

1. Check Installed JDKs

First, ensure you have the correct JDK version installed:

  • Go to the Java SE Downloads page and download the appropriate JDK version (for major version 60, this is JDK 16).
  • Install the JDK and make note of its installation path.

2. Configure IntelliJ IDEA to Use the Correct SDK

Next, configure IntelliJ IDEA to use the correct Java SDK:

  • Open IntelliJ IDEA and navigate to File > Project Structure.
  • Under the Project section on the left pane, ensure the Project SDK is set to JDK 16.
  • Also, verify that Project language level is set to the appropriate Java version (Java 16 or above).

3. Update Module SDK

Some projects may have specific module SDK settings:

  • Go to File > Project Structure > Modules.
  • For each module in the project, ensure the Module SDK is configured to JDK 16.

4. Clear and Rebuild the Project

Once the correct SDK is configured:

  • Navigate to Build > Rebuild Project to clean and rebuild your project.

Example Configuration

Here's an example of how your pom.xml might look if you're using Maven, ensuring the compiler plugin is set up correctly:

xml
1<properties>
2    <maven.compiler.source>16</maven.compiler.source>
3    <maven.compiler.target>16</maven.compiler.target>
4</properties>

Similarly, for Gradle, you can set the Java version in the build.gradle file:

groovy
1java {
2    sourceCompatibility = JavaVersion.VERSION_16
3    targetCompatibility = JavaVersion.VERSION_16
4}

5. Verify Environment Variables

Ensure that your JAVA_HOME system environment variable points to the JDK 16 installation path. Do this as follows:

  • On Windows: Navigate to Control Panel > System and Security > System > Advanced system settings > Environment Variables.
  • On macOS/Linux, you can add or modify JAVA_HOME in .bash_profile, .zshrc, or similar configuration files:
bash
  export JAVA_HOME=/path/to/jdk16

6. Revalidate Libraries and Dependencies

Sometimes, library or dependency mismatches can lead to this error. Ensure that the libraries or frameworks you're using are compatible with Java 16.

Conclusion

Encountering "unsupported class file major version 60" in IntelliJ IDEA is typically a sign that your project or build configuration is not compatible with the active JDK. By installing the correct JDK version, updating your project settings, and ensuring your environment variables are set correctly, you can resolve this problem and ensure smooth development within IntelliJ IDEA.


Course illustration
Course illustration

All Rights Reserved.