Java类文件(.class文件)版本号与JDK的对应关系
一个java的class文件是一个二进制文件,其中前四个字节是magic位,第五到第六个字节对应于minor和major,下面是这个类文件版本与JDK的对应关系:
jdk | minor | major |
1.0 | 45 | 3 |
1.1 | 45 | 3 |
1.2 | 46 | 0 |
1.3 | 47 | 0 |
1.4 | 48 | 0 |
1.5 | 49 | 0 |
1.6 | 50 | 0 |
1.7 | 51 | 0 |
所以当见到类似如下的错误时就应该知道问题出在哪里了:
错误的类文件: ...\jetty-util-8.0.4.v20111024.jar(org/eclipse/jetty/util/TypeUtil.class)
类文件具有错误的版本 50.0,应为 49.0
注:这个错误是提示你应该使用jdk1.6而不是jdk1.5。
小技巧,在class文件所在目录,可以使用javap命令查看版本号
如:javap -verbose AGateway,会显示以下内容,找到major version:
public abstract class org.smslib.AGateway extends java.lang.Object
SourceFile: "AGateway.java"
InnerClass:
#56= #29 of #54; //QueueManager=class org/smslib/AGateway$QueueManager of class org/smslib/AGateway
#58= #10 of #54; //Statistics=class org/smslib/AGateway$Statistics of class org/smslib/AGateway
public #60= #59 of #54; //GatewayAttributes=class org/smslib/AGateway$GatewayAttributes of class org/smslib/AGateway
public final #62= #61 of #54; //AsyncEvents=class org/smslib/AGateway$AsyncEvents of class org/smslib/AGateway
public final #64= #63 of #54; //GatewayStatuses=class org/smslib/AGateway$GatewayStatuses of class org/smslib/AGateway
public final #66= #65 of #54; //Protocols=class org/smslib/AGateway$Protocols of class org/smslib/AGateway
public final #136= #135 of #266; //MessageClasses=class org/smslib/InboundMessage$MessageClasses of class org/smslib/Inbo
undMessage
public final #170= #169 of #269; //DeliveryStatuses=class org/smslib/StatusReportMessage$DeliveryStatuses of class org/sm
slib/StatusReportMessage
minor version: 0
major version: 51
Constant pool:
......