How can I tell what version of the Java compiler was used to build a jar? I have a jar file, and it could have been built in any one of three JDKs. We need to know exactly which one, so we can certify compatibility. Is the compiler version embedded somewhere in the class files or jar?
Java – What version of javac built the jar
jarjava
Related Topic
- Java – a serialVersionUID and why should I use it
- Java – Fastest way to determine if an integer’s square root is an integer
- Java – How to create an executable JAR with dependencies using Maven
- Java – Efficiency of Java “Double Brace Initialization”
- Java – Can’t execute jar- file: “no main manifest attribute”
- Java – Can’t start Eclipse – Java was started but returned exit code=13
- Java – Where is Java Installed on Mac OS X
- Java – How to add local .jar file dependency to build.gradle file
Best Answer
A
jar
is merely a container. It is a file archive ā latar
. While ajar
may have interesting information contained within it's META-INF hierarchy, it has no obligation to specify the vintage of the classes within it's contents. For that, one must examine theclass
files therein.As as Peter Lawrey mentioned in comment to the original question, you can't necessarily know which JDK release built a given
class
file, but you can find out the byte code class version of theclass
file contained in ajar
.Yes, this kinda sucks, but the first step is to extract one or more classes from the
jar
. For example:On Linux, Mac OS X or Windows with Cygwin installed, the file(1) command knows the class version.
Or alternatively, using
javap
from the JDK as @jikes.thunderbolt aptly points out:For
Windows
environments without eitherfile
orgrep
FWIW, I will concur that
javap
will tell a whole lot more about a givenclass
file than the original question asked.Anyway, a different class version, for example:
The class version major number corresponds to the following Java JDK versions: