This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 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 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.
SCJP, SCWCD, SCBCD, Oracle Certified Professional (SQL n PL/SQL)
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.
Joined: Aug 27, 2002
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.
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.
Joined: Aug 27, 2002
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.
Joined: Mar 07, 2009
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.
Joined: Aug 27, 2002
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com