Binary Difference in Zip/Jar file

The binary difference is because of the timestamp of the manifest files. If you let jar create a manifest itself it will create a manifest on the fly and set the created manifest to currentTimeMillis.

You can solve it by:
1. Do not add a manifest (if your using ant you must use zip instead of jar)
2. Add the manifest like you add normal files. (So the manifest is a file on your filesystem and it isn't created on the fly)


Using the Java java.util.zip.ZipOutputStream standard library utility it is possible to create zip files with reproducible content.

The only trick is that the timestamp of the zip entries must be fixed using this trick:

ZipOutputStream zos=...;
ZipEntry ze=new ZipEntry("Filename");
zipEntry.setTime(0);
zos.putNextEntry(ze);
try
{
   zos.write(data);
}finally
{
  zos.closeEntry();
}

Tags:

Java

Jar

Zip