This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Regarding class version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding class version" Watch "Regarding class version" New topic
Author

Regarding class version

surya.raaj prakash
Ranch Hand

Joined: Oct 30, 2009
Posts: 76
Hi Friends,

When i build my application with ant tool i got a compilation error and how can i find out the class file vesion?
[javac] bad class file: D:\javahack\workspace4\javahack\lib\sanjdk.jar(com/sunn
/xml/XMLDataDOM.class)
[javac] class file has wrong version 50.0, should be 49.0
[javac] Please remove or make sure it appears in the correct subdirectory of
the classpath.
[javac] import com.sunn.xml.XMLDataDOM;
[javac] ^
[javac] 1 error
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19725
    
  20

Class version 50.0 means the class has been compiled using Java 6. You are trying to run it with a Java 5.0 JVM though. Either upgrade the JVM to 6, or use the -target flag to compile the class for a Java 5.0 environment.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
If you realy need to find out your class files version, open it with a hex editor. All classes start with CAFE BABE xxxx xxXX. Dont know what bites mean where I put the little x, but the big XX stands for version. It's in hex so 0x31 = 49 version 5.0, 0x32 = 50 version 6.0 ...


SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1794
    
    7

Martin Vanyavchich wrote:If you realy need to find out your class files version, open it with a hex editor. All classes start with CAFE BABE xxxx xxXX. Dont know what bites mean where I put the little x, but the big XX stands for version. It's in hex so 0x31 = 49 version 5.0, 0x32 = 50 version 6.0 ...


Or javap with the -verbose option.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Martin Vanyavchich
Ranch Hand

Joined: Sep 16, 2008
Posts: 241
Cool, didn't know about javap, thank you Jelle.
Poobhathy Kannan
Ranch Hand

Joined: May 26, 2004
Posts: 94
surya, it good to know how to find the class version.But I doubt that finding the class version in your class file will be helpful for resolving this issue and it is already in the error message given by ant and the class version is 50. you should use the component(sanjdk.jar) compiled with compiler compliance level 1.5, or as Rob suggested upgrade your JVM


http://learnertobeginner.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
If my Oracle download ever opens (it was so much faster from Sun) I can give you a link to the "javac" tool; there you will find what the options to compile for a particular version are.

Try here and look for the pale blue box with "javac" in, near the top left, or here and "javac" is the top line.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding class version