• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.UnsupportedClassVersionError

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,

Im trying to run a web application i downloaded from internet. I am using Eclipse and Tomcat 6.0, when i run the app im getting the following error.


Apr 26, 2009 6:52:35 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet AutoCompleteServlet threw exception
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1817)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at com.testwebsite.servlets.AutoCompleteServlet.getJsonResultAsString(AutoCompleteServlet.java:74)
at com.testwebsite.servlets.AutoCompleteServlet.doGet(AutoCompleteServlet.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)



In eclipse, i changed the project properties to use JDK 5.0
project -> properties ->Java Compiler
JDK Complaince = 5.0

if i go to command prompt and type java -version, i see the following

C:\j2ee\Apache Tomcat 6.0.14\bin>java -version
java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode)



In order to make the JRE of my PC compatible with JDK 1.5, i did the following
Windows -> Control Panel -> Java -
if i click the view button i see 3 JRE

JRE -> 1.6.0_13 ( was selected by default, and I disabled it )
JRE -> 1.5.0_14 (enabled)
JRE -> 1.4.2_09 ( was selected by default, and I disabled it )

any help on resolving this issue is appreciated.

Thanks,
Rajeev

 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rajeev,

Thee kind of situations arise when you compile your application using a particular version of Java, and then try to run it in a different version of Java [usually occurs when you compile using a higher version, and try running using a lower version]. In your case, what is the format of the webapp you downloaded ? was it a war file ? I mean did you compile the app yourself, or just received it as a set of class files ? Since you've mentioned eclipse in your query, I suppose you've compiled the source yourself... in that case, what too did you use to build the project ? ant ? maven ? Try running "ant -version" or "mvn -version" based on your build tool, on the command line and see what is the java version used by the build tool. Check if it is the same as the runtime JRE currently being used in your system... [both needs to be the same, ideally]

See if this helps... else, do let me know what were your observations after these steps.
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Dawn,

thanks for the quick reply. The file i got was a zip file, i created a dynamic web project in eclipse and copied files to the project structure. no, im not using Ant to build the app. I select run on server for index.jsp and i see the page, if i try to do more ( which is ajax, JSON example) i get run time error in the log file, which i have copied in the earlier post.

I created a Tomcat Server within eclipse and run my app on Tomcat. is it possible to check which jre version tomcat is running on ? I feel like im compiling the app using jdk 5.0 and the JRE is 6. Its just a gut feeling and im not sure how to fix it either if that is the issue.

thanks again for your reply.

-Raj
 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat uses the JAVA_HOME environment variable to decide the location of java.exe and javac.exe, not your path variable. Check the JAVA_HOME and JRE_HOME environment variables.
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
both looks good for me



C:\>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.5.0_14

C:\>echo %JRE_HOME%
C:\Program Files\Java\jdk1.5.0_14


 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somehow I managed to miss the fact that you were starting the Tomcat from within Eclipse. Have a look at this article and look for the heading “Choose a Server Runtime Environment”. You can select which jre to use for launching Tomcat.

Since you are getting a class version error I am quite confident that JRE 1.4 is being used.
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Moojid,

thanks for the link, i changed the Server JRE to 1.5.0_14 but i am facing the same issue.

I created a new TestServlet in the same web project to check what is wrong, this servlet just takes a parameter from a html page and prints on the console . It ran well and i was able to see the output, now I'm totally confused.

- raj
 
Moojid Hamid
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajeev Ravindran wrote:thanks for the link, i changed the Server JRE to 1.5.0_14 but i am facing the same issue.



I would suggest changing it to 1.6, you can always run the files compiled in older version in newer version JRE. let's see if that helps.
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i remember installing JRE lately and i think my JDK version is not compatible with JRE . Well I did change the settings to take JRE 1.5. The only option left which i can think of is to install JDK 6 and make tomcat run under the latest JRE (1.6) and see how it behaves.

thanks for you replies.

- raj
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic