[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Why am I getting "java.lang.UnsupportedClassVersionError: Arch : Unsupported major.minor version 51.0"

Published on
11,695 Points
1 Endorsement
Last Modified:
When compiling a Java source file using javac from JDK 7 the generated class file format is incompatible with previous JRE versions including version 6.

Therefore when trying to run the class file using Java 6 the following cryptic exception is thrown by Java:
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld: Unsupported major.minor version 51.0

Class version 51.0 is the version of class file generated by javac 7 while Java 6 expects class file format 50.0 or lower.

To solve the problem you need to tell javac 7 to create a class format compatible with previous versions of Java.

With previous versions of java adding the -target flag solved the problem:
javac -target 1.6 HelloWorld.java

However as of Javac 7 this command emits the following error:
javac: target release 1.6 conflicts with default source release 1.7

Adding the -source flag fixes this problem but generates a warning:
javac -source 1.6 -target 1.6 HelloWorld.java
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning

javac is warning us that we are compiling Java source code according to Java 6 source format but linking it with the Java runtime libraries of Java 7.

This works but may lead to subtle runtime bugs.

To fix the warning:
1. Install a Java 6  JRE.
2. Add the -bootclasspath flag to point to the Java 6 rt.jar from the javac 7 command line:
javac -bootclasspath <JRE 1.6 home>\lib\rt.jar -source 1.6 -target 1.6 HelloWorld.java

You should now see that the source compiles without warning and the resulting class file is executable using Java 6.

If you received a class file or a Jar file from a 3rd party and would like to see which class format version is being used, you can use a tool like the jclasslib bytecode viewer

Another concern is that if you are redistributing the JDK together with your product, in this case you'll have to distribute both the JDK 7 and JRE 6 in order for your customers to be able to compile Java 6 compatible class files using a Java 7 javac.
1 Comment

Expert Comment

very good. thanks

Featured Post

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Join & Write a Comment

Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month