Wednesday, December 12, 2012

Maven and Tomcat - UnsupportedClassVersionError unsupported major.minor version 51.0 unable to load class


This error means that the run time JDK version is older than the compiled JDK version. The solution is to make sure Maven and Tomcat pointing to the same JDK.

Check Maven version:
mvn --version
Sample Output:

Apache Maven 3.0.4 (r1232337; 2012-01-17 08:44:56+0000)
Maven home: /opt/tools/apache-maven-3.0.4
Java version: 1.7.0_09, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-31-virtual", arch: "amd64", family: "unix"


Check java version

java -version
Sample Output:
java version "1.7.0_09"
OpenJDK Runtime Environment (IcedTea7 2.3.3) (7u9-2.3.3-0ubuntu1~12.04.1)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)


Check if you have set the JAVA_HOME environment correctly.
echo $JAVA_HOME
Sample Output:
/usr/lib/jvm/java-7-openjdk-amd64

If you are sure everything is pointing to the same JDK and you still get the UnsupportedClassVersionError, check if Tomcat is using the correct JDK
vi /etc/init.d/tomcat7
Search For:
for jdir in $JDK_DIRS; do
    if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
        JAVA_HOME="$jdir"
    fi
done
export JAVA_HOME
echo $JAVA_HOME #Add this line
Now start Tomcat
service tomcat7 start 

No comments:

Post a Comment