Friday, December 07, 2007

Fun with javap

I finally was able to try out javap for the first time today. I needed to know what version of Java a class file was compiled in and javap came to the rescue! To determine the version simply run javap on the class.

javap -verbose my/compiled/class

This will dump a bunch of information about your class file. The only thing you are looking for is the major version up at the top. It should look something like this.
$ javap -verbose aTest/service/EJBHelloService
Compiled from "EJBHelloService.java"
public class aTest.service.EJBHelloService extends javax.xml.ws.Service
SourceFile: "EJBHelloService.java"
RuntimeVisibleAnnotations: length = 0x15
00 01 00 24 00 03 00 1C 73 00 25 00 26 73 00 27
00 28 73 00 29
minor version: 0
major version: 50
Constant pool:
const #1 = Method #16.#42; // javax/xml/ws/Service."":(Ljava/net/URL;Ljavax/xml/namespace/QName;)V
const #2 = Field #15.#43; // aTest/service/EJBHelloService.EJBHELLOSERVICE_WSDL_LOCATION:Ljava/net/URL;
const #3 = class #44; // javax/xml/namespace/QName
const #4 = String #39; // http://service.aTest/
...
The versions of Java go like this:

Java 6 50
Java 5 49
Java 1.4.2
48
Java 1.3.1
47
etc ...

No comments:

Post a Comment