Wednesday, June 25, 2008

Idenfiy Java Compiler Version used to compile a class

Some times we need to identify what compiler version and vendor was used for a given Java class file. We can use Jakarta BCEL to idenfiy compiler version.
Sample Java Code
import org.apache.bcel.classfile.*;
public class JDKIdentifier
{
public static void main(String[] args) throws Exception
{
printClassVersion("c:\\foo.jar", "com/foo/Bar.class");
}
public static void printClassVersion(String jarfile, String classfile) throws Exception
{
ClassParser cp = new ClassParser(jarfile, classfile);
JavaClass clazz1 = cp.parse();
System.out.println(jarfile);
System.out.println("Major: " + clazz1.getMajor());
System.out.println("Minor: " + clazz1.getMinor());
}
}
Reference
http://forum.java.sun.com/thread.jspa?threadID=577007&messageID=3791497

No comments:

ORM Framework for Kotlin

In Kotlin, ORM (Object-Relational Mapping) libraries provide a convenient way to interact with databases using object-oriented programming p...