Java : Unsupported Major.Minor Version 51.0


1. Problem

Run FormScanner on a Unix like system (Linux, MacOSX), and hits the following error messages:

$ java -jar -DFormScanner_HOME=/home/pi/formscanner-0.10.0-bin -DFormScanner_VERSION=0.10.0 /home/pi/formscanner-0.10.0-bin/lib/formscanner-main-0.10.0.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/albertoborsetta/formscanner/gui/FormScanner : Unsupported major.minor version 51.0
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(
 at Method)
 at java.lang.ClassLoader.loadClass(
 at sun.misc.Launcher$AppClassLoader.loadClass(
 at java.lang.ClassLoader.loadClass(
Could not find the main class: com.albertoborsetta.formscanner.gui.FormScanner. Program will exit.

A quick check on the Java version, shows the system is using 1.6

$ java -version
java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1~deb7u1)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

2. Reason

This is because FormScanner is compiled with JDK 1.7, but you try to run in a JDK 1.6 environment. Refer to the following Wikipedia Java class reference.

J2SE 8 = 52 (0x34 hex)
J2SE 7 = 51 (0x33 hex)
J2SE 6.0 = 50 (0x32 hex)
J2SE 5.0 = 49 (0x31 hex)
JDK 1.4 = 48 (0x30 hex)
JDK 1.3 = 47 (0x2F hex)
JDK 1.2 = 46 (0x2E hex)
JDK 1.1 = 45 (0x2D hex)

P.S major.minor version 51.0 = JDK 1.7 / 7

3. Solution

To fix it, download JDK 7, and change the default JDK from 1.6 to 1.7 (or higher). This guide works on Debian like system only.

3.1 Download and install openjdk-7-jdk

$ sudo apt-get install openjdk-7-jdk openjdk-7-jre

3.2 Change the default Java to 1.7

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
  Selection    Path                                            Priority   Status
* 0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 
to provide /usr/bin/java (java) in manual mode
$ java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1~deb7u1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s