views:

109

answers:

3

How can I do to tell if a java class was compiled for use on a java 6 vm?

Is there an easy way?

+4  A: 

It's in the class file format specification. The WP article on the subject includes the current set of version number constants.

crazyscot
I was looking more for something like a command, or just by looking at a header of the file or something like that.But your answer is the closest to what I was looking for so far.
feniix
`javap -verbose -classpath ... com.company.YourClassName` will print out the version numbers for you
matt b
since matt b didn't make that an actual answer, and no one gave the magic number (50), I added an answer of my own, and made it a little easier to just get a yes/no answer.
Kevin Bourrillion
A: 

By using a java decompiler

fastcodejava
... that doesn't go well, at least not with jd-gui. This one doesn't offer a view on a class file's metadata. (quickly tested with the actual V0.3.2). So with this method you'd have to look for the use of classes/methods that haven't been available until Java 1.6.
Andreas_D
Inexact Andreas_D, the version of the compiler is displayed by JD-GUI:drag and drop a class file and move the mouse over the tab.
Emmanuel Dupuy
+4  A: 

In unix,

$ javap -classpath <classpath> -verbose foo.Bar \
  | grep -q 'major version: 50' && echo yep || echo nope

thanks @matt b.

Kevin Bourrillion
good answer thanks!
feniix