Comparing two .jar files

How do I compare two .jar files? Both of them have compiled .class files.

I want the difference in terms of method changes, etc.


Solution 1:

  • JAPICC, sample usage:

    japi-compliance-checker OLD.jar NEW.jar

    Sample reports for log4j: http://abi-laboratory.pro/java/tracker/timeline/log4j/

    enter image description here

  • PkgDiff, sample usage:

    pkgdiff OLD.jar NEW.jar

    See sample report for args4j.

    enter image description here

  • Clirr, sample usage:

    java -jar clirr-core-0.6-uber.jar -o OLD.jar -n NEW.jar

Solution 2:

If you select two files in IntellijIdea and press Ctrl + Dthen it will show you the diff. I use Ultimate and don't know if it will work with Community edition.

Solution 3:

  1. Rename .jar to .zip
  2. Extract
  3. Decompile class files with jad
  4. Recursive diff

Solution 4:

Extract each jar to it's own directory using the jar command with parameters xvf. i.e. jar xvf myjar.jar for each jar.

Then, use the UNIX command diff to compare the two directories. This will show the differences in the directories. You can use diff -r dir1 dir2 two recurse and show the differences in text files in each directory(.xml, .properties, etc).

This will also show if binary class files differ. To actually compare the class files you will have to decompile them as noted by others.

Solution 5:

Create a folder and create another 2 folders inside it like old and new. add relevant jar files to the folders. then open the first folder using IntelliJ. after that click whatever 2 files do you want to compare and right-click and click compare archives.