File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Tomcat throws java.lang.UnsupportedClassVersionError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat throws java.lang.UnsupportedClassVersionError" Watch "Tomcat throws java.lang.UnsupportedClassVersionError" New topic
Author

Tomcat throws java.lang.UnsupportedClassVersionError

Guy Roth
Ranch Hand

Joined: Aug 09, 2009
Posts: 74
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

Joined: Aug 09, 2009
Posts: 74
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

Joined: Oct 12, 2001
Posts: 1179

Have you set Eclipse Compiler options (source and target) to the Java version that your Tomcat runs with??

Regards, Rene Larsen
Dropbox Invite
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Here is another thread about your problem: http://www.coderanch.com/t/292805/JSP/java/Bad-version-number-class-file
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat throws java.lang.UnsupportedClassVersionError