aspose file tools*
The moose likes Beginning Java and the fly likes java.lang.UnsupportedClassVersionError: Bad version number in .class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.UnsupportedClassVersionError: Bad version number in .class file" Watch "java.lang.UnsupportedClassVersionError: Bad version number in .class file" New topic
Author

java.lang.UnsupportedClassVersionError: Bad version number in .class file

Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
I am having an issue running my servlet. Can anyone help me figure out why I am getting the bad version error? Below also are my servlet code and my path and classpath info. I am using Orion 2.0.7 for the app server.

I am receiving the following:

500 Internal Server Error
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._as.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._ay._lye(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._ay._cbd(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._ay._nlc(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._ax._lsc(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._ax._uab(Unknown Source)
at com.evermind[Orion/2.0.7 (build 11273)]._bf.run(Unknown Source)

Can anyone help me figure out why I am getting the bad version?


Below is my servlet and my path and classpath info that may help.

My servlet is BeeServlet copied directly from the Cattle Drive.

import java.io.* ;
import javax.servlet.http.* ;

public class BeeServlet extends HttpServlet
{

public void doGet( HttpServletRequest request , HttpServletResponse response )
{
response.setContentType("text/html");
try
{
PrintWriter out = response.getWriter();
out.println( "a-buzz-buzz ..." );
out.close();
}
catch( Exception e )
{
System.out.println( "cannot get writer: " + e );
}
}

}


The follow are my path and classpath configuration:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Owner>cd c:\java

C:\java>cd c:\orion

C:\orion>echo %path%
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Sun\SDK\bin;c:\Sun\SD
K\jdk\bin;c:\Sun\SDK\jdk\jre\bin;C:\Sun\AppServer\bin

C:\orion>echo %classpath%
.;c:\Sun\SDK\lib\j2ee.jar;c:\StudentWork\jr.jar

C:\orion>java -jar orion.jar
Orion/2.0.7 initialized

As you can see I'm using Orion 2.0.7 for the app server.


If I am lacking any other info, please let me know.

Thanks
Jim

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

UnsupportedClassVersionError means that the class that you are trying to use was compiled in a version of Java that the Java Runtime doesn't support - usually it means the class was compiled in a newer version of Java than the one running the code.

So you need to find out what version of Java your Orion server supports and re-compile your classes to be compatible with that version of the JRE.


Steve
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19785
    
  20

That exception is thrown when you compile a class using a later Java version than the JRE that is running the class. For example, if you compile a class with a Java 5.0 compiler and then try to run it with a Java 1.4 JRE.

The -source and -target compiler flags can help you out with that.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
Steve and Rob,
Thanks for the advice. I know that the Orion 2.0.7 is used only up to J2EE 1.3. I tried to find earlier versions of Java EE on Sun's website, but when I clicked on the link for earlier versions, it took me to the downloads for J EE 5.

Would either of you know where to find the earlier versions of Java EE?

Alternatively, would you suggest using a different server? There is an Orion 2.0.8 which I couldn't tell what versions of Java EE it supports from there website, there is also the app server that came with Java EE 5 when I downloaded it.

Any suggestion would be much appreciated.

Thanks again guys,
Jim
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Javac tool web page. Look for the -source and -target tags which Rob mentioned earlier. That might be the easiest way to start. Make sure you only use Java methods and keywords which were available in JDK1.3, so no assert or enum or boxing or for-each loops or generics.
Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
Steve and Rob,
Thanks again, I got it to work after compiling it with Rob's suggestion using -source and -target to change the compiled class to version 1.4.

Thanks again.
Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
Thank you too, Ritchie.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You're welcome
 
Consider Paul's rocket mass heater.
 
subject: java.lang.UnsupportedClassVersionError: Bad version number in .class file