I have an Ant-based build system and I thought I might write a python script to test all compiled / jarred classes in a directory hierarchy so as to avoid problems that might arise from different version being used in compile time versus runtime.
Naively the script initially checked the sha256 hash of all classes found in various jar, war and ear files and complains if the same class is found with a different hash. However this produces too many false alarms.
For instance the class org.apache.commons.collections.FastHashMap is available in both commons-beanutils-1.8.0.jar and commons-collections-2.1.1.jar with different hashes. Obviously this criterion was too strict. In the end however, the only way I could produce the same hash was by doing the following:
javap commons-beanutils-1.8.0.jar.exploded/org/apache/commons/collections/FastHashMap.class | sort | grep -v Compiled\ from\ | sha256sum -
javap commons-collections-2.1.1.jar.exploded/org/apache/commons/collections/FastHashMap.class | sort | grep -v Compiled\ from\ | sha256sum -
And these are indeed the same, but this, (especially the grep -v and the sort) is very unsatisfactory. Is there a better way to test that all classes in a directory hierarchy are compatible so as to avoid unexpected runtime problems?