Is there a way to find out the JDK version used to build a .jar file?
Almost all of JCL is stored in a single Java archive file called "rt. jar" which is provided with JRE and JDK distributions.
That's not possible reliably, since you don't even need a JDK to build a JAR file - it's just a ZIP file with the classes and a manifest file inside.
What you can find out is what version of the class file format is used. The major version number maps to majorJDK releases:
J2SE 6.0 = 50 (0x32 hex)
J2SE 5.0 = 49 (0x31 hex)
JDK 1.4 = 48 (0x30 hex)
JDK 1.3 = 47 (0x2F hex)
JDK 1.2 = 46 (0x2E hex)
JDK 1.1 = 45 (0x2D hex)
However, the java compiler has an option to use the class file format of a previous version, which is frequently used to achieve downwards compatibility. But if you find a class file version major number of 50, you know that the classes were definitely not compiled with a Java 5 or earlier JDK.
In the Jars MANIFEST.MF there may be a Build-Jdk property which should be what you're looking for.
You can extract the class files from the jar file and use the following command:
javap -verbose SomeClass | grep major
Should give you the version number of the class files.
Most jars are built using the provided "jar" tool packaged with the jdk.
In SUN's JDK the provided "jar" tool will add a "Created-By" line in the embedded META-INF/MANIFEST.MF file.
That line will specify the version of the JDK that created the JAR (in my case "Created-By: 1.6.0_17 (Sun Microsystems Inc.)")
Other Java vendors tend to do the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With