wood burning stoves 2.0*
The moose likes Servlets and the fly likes Getting error: Bad version number in .class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting error: Bad version number in .class file " Watch "Getting error: Bad version number in .class file " New topic
Author

Getting error: Bad version number in .class file

Mayank Kalbhor
Greenhorn

Joined: Feb 26, 2011
Posts: 17
Hi all,

Need some help. I created a simple servlet from VTC tutorials. The problem i compile the servlet and put it in exact directories mentioned in the tutorial but after deployment of the app(war file) in j2ee web container i am getting this error.

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:1798)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:910)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1375)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1239)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:189)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.doProcess(ProcessorTask.java:604)
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:475)
com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:371)
com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:264)
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:281)
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:83)


after googling I came to know this happens due to conflicting versions of java while compiling and running. I am using "C:\Program Files\Java\jdk1.6.0_21" as JDK and "j2eesdk-1_4_03-windows" as the container. Can you please how can i downgrade the JDK path in EV.? How can i match the versions so that i am able to compile.

Thank you in advance.

Mayank kalbhor
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
j2eesdk-1_4_03 is way, WAY, obsolete - time to get rid of it.

If it's just servlets and JSPs you're interested in use Tomcat 6 (or 7) as the container, and make sure it also uses Java 6 (or jdk1.6, as it's sometimes called).

As an aside, in the future please UseAMeaningfulSubjectLine.


Ping & DNS - updated with new look and Ping home screen widget
Mayank Kalbhor
Greenhorn

Joined: Feb 26, 2011
Posts: 17
Thank you ulf for a quick response. I am downloading Tomcat 7 now.

Thanks a lot...


Mayank
Arvind Gangwar
Ranch Hand

Joined: Mar 25, 2010
Posts: 37

Howdy Ulf,
I am also new one , but as i know, you are eight, that your problem is because of conflicting versions of java.
So you should try ...this as..
1-
You should change the path variable in both in User variable as well as in System variable.....as i think you changed your path only in system variable...so you should change it on both place..
2. copy your jdk 1.4 path from your container whichever is the path and past in path variable in both places.

then open your command prompt again... and try...
i hope it may solve your problem....

But if i am wrong then please forgive me for my unusual suggestion...

Arvind Gangwar
OCPJP 6
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
Arvind Gangwar wrote:But if i am wrong then please forgive me for my unusual suggestion...

Your suggestion is not technically wrong, but using Java SE 1.4 or Java EE 1.4 at this point is just asking for trouble. Both have been obsolete for years, and should be phased out as soon as possible. Certainly no new development should use either (or Java SE 5, actually).
Arvind Gangwar
Ranch Hand

Joined: Mar 25, 2010
Posts: 37

hi
you are right dear but i just try to answer what you ask in this thread...as you asked how can i downgrade the JDK path in EV.? How can i match the versions so that i am able to compile.

so keep it up...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
Arvind Gangwar wrote:i just try to answer what you ask in this thread...

I understand, but sometimes the best way to answer a question is to challenge the underlying assumptions. (And please note that it wasn't me who asked the question - Mayank Kalbhor did.)
Mayank Kalbhor
Greenhorn

Joined: Feb 26, 2011
Posts: 17
I actually installed JEE 6 (Glassfish). The problem was solved.

Mayank
parampreet sethi
Greenhorn

Joined: Aug 03, 2009
Posts: 27

I have faced a similar problem when my eclipse was using jdk 6 and compiling the code in jdk 6. How ever my tomcat was using java 1.5. And at runtime I was getting "Bad version number in .class file" error.


Param
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting error: Bad version number in .class file
 
Similar Threads
Problem with the first example of HFSJ
Error 500 when compiling servlet
Bad version number
java.lang.UnsupportedClassVersionError
Change Tomcat's JDK Version