How can ant compile-and-jar byte-identical jar files, i.e. so MD5 matches unless .java (and thus .class) changes?

前端 未结 3 1353
庸人自扰
庸人自扰 2020-12-28 09:17

Summary

How can you make ant repeatedly generate byte-identical jar files from the same .class files?

Background

Ou

3条回答
  •  星月不相逢
    2020-12-28 09:56

    Had this same problem, landed on this page. The answer above by Jiri Patera was very helpful in understanding why I could not get the md5sums of what I expected to be two identical files to be the same after unsigning and resigning the jar files.

    This is the solution I used instead:

    jar -tvf $JARFILE | grep -v META-INF | perl -p -e's/^\s+(\d+).*\s+([\w]+)/$1 $2/g' | md5sum

    It doesn't give 100% certainty that the jars are equivalent but it gives a fairly reliable indication.

    It takes a listing of all the files in the jarfile minus the META_INF files, parses out file size and file name, and then runs the text of filesizes plus filenames thru the md5sum algorithm.

提交回复
热议问题