Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes java.lang.UnsupportedClassVersionError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.lang.UnsupportedClassVersionError" Watch "java.lang.UnsupportedClassVersionError" New topic
Author

java.lang.UnsupportedClassVersionError

Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
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


SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
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

Joined: Aug 27, 2002
Posts: 455
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
Moojid Hamid
Ranch Hand

Joined: Mar 07, 2009
Posts: 120
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

Joined: Aug 27, 2002
Posts: 455
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

Joined: Mar 07, 2009
Posts: 120
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

Joined: Aug 27, 2002
Posts: 455
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

Joined: Mar 07, 2009
Posts: 120
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

Joined: Aug 27, 2002
Posts: 455
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.UnsupportedClassVersionError