1

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?

4

1 に答える 1

1

アプリケーションを本番環境にデプロイする前に、アプリケーションをテストすることをお勧めします。必要ないと思われるライブラリがある場合は、それらを削除するか、テストする必要があります。

開発でさえ使用したことがないライブラリを本番環境で実行するべきではありません。

これにより、本番環境で発生する可能性のあるさまざまな問題が最小限に抑えられます。

于 2013-01-10T10:19:04.060 に答える