What version of javac built my jar?
Determine the javac
version that constructed a .jar
file by extracting its .class
files and inspecting the class file's major
version number. Run these commands:
What does this major
version number tell us? It's a mapping to the Java version:
- 52 connotes Java 8
- 55 represents Java 11
- 59 signifies Java 15
In essence, all we need is the first occurrence to perform our compiler version magic trick.
Quick guide on bytecode skimming
When you invoke the javap -verbose
command, it's akin to opening Pandora's box - a treasure trove of information.
- Class versions for JVM compatibility: The class file version mainly suggests the earliest Java Runtime that can process it - not specifically the
javac
version. - Hex editors - the magnifying glass on bytecode: Dive into details by inspecting byte offsets 4-7 in class files with a hex editor, if you dare 😉.
- Manifest insights: Peek into the
MANIFEST.MF
hiding in theMETA-INF
directory. It might contain the JDK version. It's like a letter from the compiler - if you're lucky. - Command line tools: Unix systems flaunt their
file
command. Windows with Cygwin installed has its arsenal too. They're like pocket magnifying glasses for file information.
Deciphering the major version numbers
The major
version numbers seem cryptic like a cipher but follow a consistent pattern. Understanding these patterns ensures seamless integration of Java applications on diverse environments. Here's your secret decoder ring:
Major Version | Java Version |
---|---|
50 | 6 |
51 | 7 |
52 | 8 |
... | ... |
You can find this Rosetta stone in the official Java class file documentation or a detailed table like the one on Wikipedia.
Unearthing secrets without unboxing
What if the .class
file's version needs to be checked without extracting the .jar
file? We can equip our command line armor again:
Replace com.myapp.Main
with your specific package and class name. Jane Austen would be proud - so much drama without much fuss.
Toolkit for the modern archaeologist
Feeling intimidated by the jargon or flashy command-line prowess? Fear not. We have a flourishing ecosystem of libraries and tools:
- Apache Commons BCEL: An analysis weapon to detect
javac
version without getting your hands dirty. - Bytecode Viewer: An advanced Swiss army knife for digging deep into bytecode.
- Java Decompiler: A handy photon cannon to light up the darkest corners of the
.jar
file.
Was this article helpful?