. Advertisement .
..3..
. Advertisement .
..4..
The error: “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
Why does the error “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0” happen?
When updating IntelliJ, you may get the following problem.
D:\MyProject\ProjectExcercise\src>java com.codewithmosh.Main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread “main” java.lang.UnsupportedClassVersionError: com/ssc/Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
This error indicates that the Java version which you used to compile your class was higher than the Java version you used to attempt to run it. More specifically, in this instance, you attempted to run your class using Java 8 and compiled it with Java 13. Therefore, the error “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0” occured.
How to solve the error: “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0”
Approach 1: In IntelliJ IDEA, change the following setting
- Firstly, open IntelliJ IDEA and select File.
- After that, go to Settings.
- Choose Build, Execution, and Deployment from the drop-down menu. Gradle, now.
- Then there’s the Gradle JVM.
- Choose, for example, Project SDK (corretto-1.8) (or any other compatible version).
- Next, restart the IDE after deleting the build directory.
Approach 2: Choose SDK default
Choosing SDK default also is a way to fix “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0” error. Let’s follow these steps:
- To begin with, go to “Project Structure.”
- Next, choose a project.
- Choose a language level for the project.
- Then, choose SDK default.
- For all project modules, the SDK should be the same.
- Your problem should now be resolved.
Approach 3: Include environment PATH
You have to include the PATH environment variable. The current location of C:\Program Files\Java\jdk-13 is incorrect. Simply place the bin subfolder for the most recent JDK version at the top of your PATH list. Because the java.exe executable is located in the C:\Program Files\Java\jdk-13\bin directory, you must include it in your PATH.
Include this in the PATH variable:
C:\Program Files\Java\jdk-13\bin
Approach 4: Use Maven
Excepting the mentioned above approaches, using Maven is a great way to solve “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0” error.
The Java version that you want can be controlled when you creat and package any files in Maven. You can set the source and target for the compiler plugin while you are running Java 8 or even earlier by utilizing the plugin properties of compiler. Look at the following code to further understand:
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
Moreover, the source and target can also be configured in the compiler plugin as below:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment