how to check the jdk version used to compile a .class file

Java

Java Problem Overview


> Possible Duplicate:
> Tool to read and display Java .class versions

I'm trying to debug a >"Bad version number in .class file'

error in java, is there a way for me to check which version the .class files are?

I'm using JRE1.5.0_6, but my JDK is version 1.6.0_13.

I'm compiling with compatibility mode set to 1.5 in eclipse which I thought would work...

Java Solutions


Solution 1 - Java

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
  • Java 9 uses major version 53
  • Java 10 uses major version 54
  • Java 11 uses major version 55

Solution 2 - Java

Btw, the reason that you're having trouble is that the java compiler recognizes two version flags. There is -source 1.5, which assumes java 1.5 level source code, and -target 1.5, which will emit java 1.5 compatible class files. You'll probably want to use both of these switches, but you definitely need -target 1.5; try double checking that eclipse is doing the right thing.

Solution 3 - Java

Free JarCheck tool here

Solution 4 - Java

You can try jclasslib:

https://github.com/ingokegel/jclasslib

It's nice that it can associate itself with *.class extension.

Solution 5 - Java

Does the -verbose flag to your java command yield any useful info? If not, maybe java -X reveals something specific to your version that might help?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCharles MaView Question on Stackoverflow
Solution 1 - JavaJohn CalsbeekView Answer on Stackoverflow
Solution 2 - JavaSean ReillyView Answer on Stackoverflow
Solution 3 - JavaGwyn EvansView Answer on Stackoverflow
Solution 4 - JavamarekdefView Answer on Stackoverflow
Solution 5 - JavaAlex MartelliView Answer on Stackoverflow