Search code examples
javajarzip

Binary Difference in Zip/Jar file


It seems like building a jar or zip from the exact same source files will always yield a different file. I tried this both using the java jar command, and the jar and zip tasks in ant.

It appears to be due to the fact that new jars/zips have the timestamp set to the current time on each stored file.

Is there a way to force a zip tool to simply use the timestamp on the file on the filesystem to ensure that a jar built from the exact same source will appear exactly the same?


Solution

  • Ok, a coworker and I came up with a solution that works for us.

    Instead of reengineering our entire build process to not delete any class or jar files, we use this procedure:

    1. Build new artifacts.
    2. Use jardiff (part of jnlp) to compare changes from previous build.
    3. If the diff jar that jardiff produces has no changes, get artifact from previous build.

    Yeah, I know it sounds kludgy, but it sure beats rewriting build script to take this into account. Also, we can do a completely clean build on a fresh machine (in the case of server failure), and this process will ensure that only actually updated jars are produced.