java.lang.UnsupportedClassVersionError: bad major version at offset=6
Asked Answered
C

4

10

I have deployed a WAR file in the webapps folder in my tomcat. And when I am starting my tomcat, like below

C:\apache-tomcat-6.0.35\bin>startup.bat
Using CATALINA_BASE:   "C:\apache-tomcat-6.0.35"
Using CATALINA_HOME:   "C:\apache-tomcat-6.0.35"
Using CATALINA_TMPDIR: "C:\apache-tomcat-6.0.35\temp"
Using JRE_HOME:        "C:\Program Files (x86)\IBM\RationalSDLC\Common\Java5.0\jre"
Using CLASSPATH:       "C:\apache-tomcat-6.0.35\bin\bootstrap.jar"

I am getting this below exception-

SEVERE: Error deploying web application archive DirectoryServer.war
java.lang.UnsupportedClassVersionError: (com/services/rest/Listener) bad major version at offset=6 (unable to load class com.services.rest.Listener)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2822)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.catalina.startup.WebAnnotationSet.loadClassAnnotation(WebAnnotationSet.java:145)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:73)
    at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:56)
    at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1078)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4612)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

And this is my JAVA version-

C:\apache-tomcat-6.0.35\bin>java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

Can anyone provide any suggestion why is it happening?

Circumvolution answered 11/10, 2012 at 23:52 Comment(0)
F
20

You have essentially compiled your code with JDK 1.6 but running it with Java 5 - Just ensure a Java 6 runtime.

Fidler answered 12/10, 2012 at 0:3 Comment(1)
this occurs generally when you compile in one version of java then run in a slightly different versionCilicia
J
2

Even I faced same problem. The problem is inappropriate class version, for ex. compiling with different jre.

Solution: IF you are using Eclipse or RAD, set change compiler setting as per your requirement and also change same setting to project configuration by clicking on "Configure Project specific setting". Windows->Preferences->Compiler-> click on link "Configure Project specific setting".

Jehius answered 29/8, 2013 at 4:42 Comment(2)
I don't see any added value in your answer, Biju Kunjummen already provided a good answerArchimage
For me solution in RAD was to change java version in run configurations for jUnit (tests failed with this error).Lacielacing
B
1

For me the fix was to set the JAVA_Home system variable to the correct path.

JAVA_Home system variable

Bolduc answered 29/8, 2017 at 18:36 Comment(0)
A
-1

It is a compiler issue. Make sure all your modules are configured with java 1.5 as a compiler. Window-->preference--> Java --> Compiler. Make sure 1.5 is selected.

Arnitaarno answered 13/2, 2017 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.