I have a java class file. How do I find out the version of the compiler used to compile this file? I'm on Ubuntu Server 12.04.
Asked
Active
Viewed 3.0k times
3 Answers
22
The JDK includes a javap command. It gives a lot information, but you can use it like this:
javap -verbose yourClass | grep version
Example output:
minor version: 0
major version: 51
The major version tells you which version the compiler had:
J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
Jules
- 103
- 3
15
Again the file(1) utility and libmagic(3), on which it is based, can be your friend:
$ file Gwan.class
Gwan.class: compiled Java class data, version 50.0 (Java 1.6)
0xC0000022L
- 10,908
- 9
- 41
- 79
-
-
1@avgvstvs: then you can still resort to something like Cygwin. Honestly, if you limit your own toolset by restricting your RCE efforts to a single host OS, that's your own fault. Simply put: know what tools to use when and don't be picky based on arbitrary and artificial limitations. – 0xC0000022L Apr 27 '14 at 18:24
-
3Cygwin introduces an unnecessary dependency. If you're reversing .class files, on every* JVM you're going to have access to
javap. I don't disagree with the rest of what you're saying, but I'm lazy and if I don't have to start a vm or d/l cygwin I'm happier. – avgvstvs Apr 27 '14 at 19:52
0
You're looking for this on the command line (for a class called MyClass):
On Unix/Linux:
javap -verbose MyClass | grep "major"
On Windows:
javap -verbose MyClass | findstr "major"
You want the major version from the results. Here are some example values:
- Java 1.2 uses major version 46
- Java 1.3 uses major version 47
- Java 1.4 uses major version 48
- Java 5 uses major version 49
- Java 6 uses major version 50
- Java 7 uses major version 51
- Java 8 uses major version 52
javacsupports the-targetor--releaseflag to generate class files targeted at earlier versions of the JDK. – David Phillips Dec 29 '18 at 03:50