
Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
On Mon, 16 Jan 2006 01:51:53 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :
>Is there a utility that will check the target versions of all classes
>in a jar to make sure they are in within a given range?
I though I would write one since nobody spoke up quickly.
Writing this utility should be pretty simple. A class file starts
with hex CAFEBABE
following by two unsigned binary shorts, the minor then the major
version number. This ordering is strange given otherwise everything
the file is MSB first.
the catch is these DON'T match the version numbers we are used to e.g.
1.5.0.
I have noticed that
when I target earlier versions:
1.1 -> major version 45
1.3 -> major version 47
1.4 -> major version 48
1.5 -> major version 49
It would be nice to check minor version as well.
Has anyone seen a table converting human version numbers to class file
minor versions?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
On Mon, 16 Jan 2006 01:51:53 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :
>Is there a utility that will check the target versions of all classes
>in a jar to make sure they are in within a given range?
I have written a crude one that checks the major version number in the
class files in a jar, e.g. whether is java 1.0, 1.1 ... 1.6.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 16 Jan 2006 10:37 GMT
On Mon, 16 Jan 2006 08:41:07 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :
>I have written a crude one that checks the major version number in the
>class files in a jar, e.g. whether is java 1.0, 1.1 ... 1.6.
JarCheck version 1.0
Check a jar to make sure all the javac -target versions of
the class files are what you expect.
Java application.
Requires Java version 1.5 or later.
Copyright (c) 2006 Canadian Mind Products.
May be used freely for any purpose but military.
All Java source code is included.
to use:
java -jar jarcheck.jar jartotocheck.jar 1.1 1.4
where jartocheck.jar is the name of jar to check.
It will check all the class files in it.
In this example:
1.1 is the lowest acceptable target version number.
1.4 is the highest acceptable target version number.
Currently, only version numbers 1.0, 1.1, 1.2, 1.3, 1.4, 1.5
and 1.6 are supported. The program does not currently test
minor version numbers.
Why would you use this utility? To make sure that a jar
intended to run under an old 1.1 JVM contains no classes
accidentally compiled with javac -target 1.5. Passing this
test does not guarantee the jar will work on an old JVM. The
jar still might use methods not bundled with old JVMs. This
should catch however, classes normally compiled with target
1.1 that were accidentally compiled with 1.5 as a side
effect of compiling some 1.5 class.
You can download it from
http://mindprod.com/products1.html#JARLOOK

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.