Debugging Java version issues

1. Error: Unsupported major.minor version 51.0 error?

What does this error mean?

The above error means what version of the JRE that the class file is compatible with. “org/apache/cxf/management/annotation/ManagedResource” was compiled with based on the following

So, “51” means it is compatible with “J2SE 7 “. If you run the above within JRE1.6 or earlier versions in an application server, you will get the above error.

Check the documentation of the framework

“CXF 3.1 no longer supports Java 6. You must use Java 7 or Java 8.”

Fix?

You either

1) run it in an applicatin server container compatible with J2SE 7 or greater

2) change version of the Apache CXF library that is compatible with J2SE 6.0. So, in the pom.xml file you can go from

to the version that was compiled with J2SE 6.0

Another common error is

2. java.lang.UnsupportedClassVersionError

Happens because of a higher JDK during compile time and lower JDK during runtime. This can be fixed

within eclipse

by going to Window -> Preferences -> Java -> Compiler and then set “Compiler compliance level” to 1.6.

outside eclipse

by setting your $JAVA_HOME (in Unix) or %JAVA_HOME (in Windows) environment variable to right JDK version. You can then check the version of your Java with

If you are building your package with Maven, you also need to check your pom.xml file for the version of the Java used.

Check your server installation if it was installed on an older version.

How do you know what version of Java was used to compile a class or a jar file?

If it is a jar file, extract a class file from the jar. “javap” is shipped with your JDK

In Unix

We are interest in the major version:

51 means Java 7.


300+ Java Interview FAQs

800+ Java Interview Q&As

Top