I have a requirement to compare two jar files(same size) and determine whether they are built out of exact same source files. Is there a way to determine this ?Are there any tools available? Any suggestions ? (PS :At the moment I do not have access to the source to build a new jar ) TIA Krishna
Programming is Fun.
Joined: Jan 23, 2002
Can you trust that the .class files were compiled using the same compiler? Can you "fail" the comparison test because the other .jar file has a different manifest.mf or some other non-code resource? The simplest option would be to calculate a hash (MD5 for example) from the .jar file's raw bytes and compare those. You could also, read the .jar files' contents using java.util.jar.* and do the same hash comparison for each file individually (filtering out any irrelevant files). If the hashing stuff doesn't seem to fit, you could try exploding the jar files somewhere, run a decompiler on them, and then compare the resulting source files. Yet another way could be to compare the timestamps within the .jar files (assuming that the original timestamps were preserved when the .jar file was created).