[Solved] Java UnsupportedClassVersionError : Compiled by a more recent version of the Java Runtime (class file version X), this version of the Java Runtime only recognizes class file versions up to Y


The java.lang.UnsupportedClassVersionError is a sub-class of LinkageError and ClassFormatError. The JVM (Java Virtual Machine) throw this error when try to read a file but Major and Minor Java version are not supported.

This Java Major and Minor class error occurred while running through IDE eclipse/STS or any because you JAVA_HOME or path or IDE Build Path is configured with different version of Java (JDK/JRE) however your code is compiled with different version of IDE. or Maven pom.xml is configured with different java version while running the program over different JDK/JRE which is not match with Major and Minor version supported.

In further post you will get to know about the resolution steps.

Example of Error Messages:

  • Java

java.lang.LinkageError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Springboot

java.lang.UnsupportedClassVersionError: XYZ has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

  • Maven

class file has wrong version 61.0, should be 55.0

Java Major Version

These are the Java Major Versions

JavaMajor Version
2064
1963
1862
1761
1660
1559
1458
1357
1256
1155
1054
953
852
751
650
549
1.448
1.347
1.246
1.145
1.0.245

How to check Java Major Version?

Yu can run the below command in your command prompt.

javap -v <path to class file> | grep "major"

Example

$ javap -v build/classes/com/FacingIssuesOnIT/Book.class | grep “major”

How to fix Java Major and Minor Version Issue?

Follow these steps to resolve Java Major & Minor version issue:

Step 1: Go to command prompt and check for Java version

Step 2: In case your system is having more than one version of Java and you want to run your application or code with specific version, then go to Application-> Right click->Select Properties->Go to Build Path->Go to Library and remove the default Library from Class Path and Module Path.

Step 3: Click on Add Library Button and Select JRE System Library, click on Next button. If your JRE on default then select or go to alternate JRE and select Java path as below by Browse button. Click on Apply and Close button and then Finish button

Step 4: Now go to the left panel and select correct compiler version as below and click on apply button.

Step 5: If your application is Maven based then you have to make additional changes in your pom.xml also

Properties Section

<properties>
		<java.version>20</java.version>
</properties>

Plugins Section

   <plugins>    
           <plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>20</source>
					<target>20</target>
				</configuration>
			</plugin>
		</plugins>

Now save all your changes and run your application or program. It will work fine.

Reference

https://en.wikipedia.org/wiki/Java_class_file#General_layout

Conclusions

In this post you have learned about the Java Major and Minor version and also to check way of checking through command prompt. If you are facing such exceptions also provided way to resolve it.

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

Leave a comment