Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat throws java.lang.UnsupportedClassVersionError

 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very wired problem:
I tried to impot to eclipse an application that I usually develop on another machine.

After importing configuring and running most of the application run fine apart from one annoying servlet that whenever I call it I get the error:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
java.lang.ClassLoader.defineClass1(Native Method)

Only this server. I know that normally java throws this errro as a result of compiling on one version and running on lower version, but this is not the situation. The rest of the servlets works just fine. So I thought, why not creating in Eclipse a new servlet call it in another name, copy to it the same content like the problematic serlet and bind the url pattern to the new servlet.
It worked at first only when performing GET method to the new Servlet. on Post I got HTTP error 405. but then after a few runs I got back to the state that after every request GET or POST I recieve the error:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
java.lang.ClassLoader.defineClass1(Native Method)

with the new Servlet class.

I really don't unsderstand what is going on. I tried to run it on Tomcat outside eclipse environment and got the same behavior.

I admit that on the original mahcine where the application work fine I run it on JDK 1.6 and Tomcat 6 and in the new machine it's JDK 1.5 and Tomcat 5.5 but I cleaned and built all the classes on the new environment again, just used the same sources. In addition that doesn't explain why it works fine in 90% of the serlets and why the same servlet sometimes works and sometimes not.

Has anyone has a vague idea what could have caused it?
 
Guy Roth
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to refine my question - Is it possible that the cause of this error is different then running the class in earlier version that it was compiled?
What other case could lead to this error:

javax.servlet.ServletException: Error instantiating servlet class rtm.servlets.SearcherServletAfter
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)


root cause

java.lang.UnsupportedClassVersionError: Bad version number in .class file
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1876)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:889)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1353)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
java.lang.Class.getConstructor0(Class.java:2671)
java.lang.Class.newInstance0(Class.java:321)
java.lang.Class.newInstance(Class.java:303)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)


 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you set Eclipse Compiler options (source and target) to the Java version that your Tomcat runs with??
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is another thread about your problem: http://www.coderanch.com/t/292805/JSP/java/Bad-version-number-class-file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic