1

Can I inspect java code and determine what runtime it will be able to run on? For instance I want to make sure all applications in our environment are using Sun SE6 and JDK 1.6.

Brig
  • 10,211
  • 12
  • 47
  • 71

2 Answers2

4

When you run the "javap -verbose" on any class, you will get a major and a minor version numbers. Following is a mapping between major+minor to an actual java jre version.

major  minor Java platform version 
45       3           1.0
45       3           1.1
46       0           1.2
47       0           1.3
48       0           1.4
49       0           1.5
50       0           1.6

If you want to programatically get the class version, you can follow this link: Java API to find out the JDK version a class file is compiled for?

Community
  • 1
  • 1
M99
  • 1,859
  • 10
  • 28
  • 50
1

javap might be what you want:

javap -verbose MyClass
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
  • So an automated release process could just run this command against a jar or war? – Brig Jan 05 '11 at 18:58
  • The problem is, it looks classname-based, so you'd need to get a list of all the classes in the .jar files in order to query them. In the case of .war you'd need to unpack the .jar files out of it in order to do that. Not ideal really, but at least it's a supported tool. – trojanfoe Jan 05 '11 at 19:09
  • Hmm.. Looks like verbose isn't showing what version of the runtime the code can run with. – Brig Jan 05 '11 at 19:11