Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Which version was a .jar file built too? [duplicate]

Tags:

java

jar

Is there a way to find out the JDK version used to build a .jar file?

like image 504
Ash Burlaczenko Avatar asked Dec 14 '10 15:12

Ash Burlaczenko


People also ask

Which JAR file in jdk1 7 version do JCL classes run?

Almost all of JCL is stored in a single Java archive file called "rt. jar" which is provided with JRE and JDK distributions.


4 Answers

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.

like image 73
Michael Borgwardt Avatar answered Sep 22 '22 09:09

Michael Borgwardt


In the Jars MANIFEST.MF there may be a Build-Jdk property which should be what you're looking for.

like image 34
Jim Avatar answered Sep 19 '22 09:09

Jim


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.

like image 23
Nayeem Zen Avatar answered Sep 20 '22 09:09

Nayeem Zen


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.

like image 26
Edwin Buck Avatar answered Sep 22 '22 09:09

Edwin Buck