Comparing two .jar files

How to compare two .jar files? Both of them compiled .class files.

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

+83
java comparison jar diff
Oct 06 2018-10-10T00:
source share
11 answers
+86
Feb 13 '12 at 19:38
source share
  • Rename .jar to .zip
  • Extract
  • Decompile class files with jad
  • Recursive diff
+18
06 Oct 2018-10-10T00:
source share

If you select two files in IntellijIdea and press Ctrl + D , then it will show you diff. I use Ultimate and don’t know if it will work with Community edition.

+11
Jun 22 '17 at 10:19 on
source share

I use in ZipDiff lib (there are both Java and ant APIs).

+5
02 Feb 2018-12-12T00:
source share

Extract each jar to your directory using the jar command with xvf options. those. jar xvf myjar.jar for each jar.

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

It will also show if binary class files are different. To really compare class files, you will have to decompile them, as others have noted.

+4
Oct. 06 '10 at 3:25
source share

On Linux / CygWin, a handy script I use from time to time:

 #Extract the jar (war or ear) cd dir1 jar xvf jar-file1 for i in `ls *.class` do javap $i > ${i}.txt #list the functions/variables etc done cd dir2 jar xvf jar-file2 for i in `ls *.class` do javap $i > ${i}.txt #list the functions/variables etc done diff -r dir1 dir2 #diff recursively 
+2
Mar 26 '15 at 0:12
source share

Here is my script to execute the process described by sje397:

  #!/bin/sh # Needed if running on Windows FIND="/usr/bin/find" DIFF="diff -r" # Extract the jar (war or ear) JAR_FILE1=$1 JAR_FILE2=$2 JAR_DIR=${PWD} # to assign to a variable TEMP_DIR=$(mktemp -d) echo "Extracting jars in $TEMP_DIR" EXT_DIR1="${TEMP_DIR}/${JAR_FILE1%.*}" EXT_DIR2="${TEMP_DIR}/${JAR_FILE2%.*}" mkdir ${EXT_DIR1} cd ${EXT_DIR1} jar xf ${JAR_DIR}/${JAR_FILE1} jad -d . -o -t2 -safe -space -b -ff -s java -r **/*.class cd .. mkdir ${EXT_DIR2} cd ${EXT_DIR2} jar xf ${JAR_DIR}/${JAR_FILE2} jad -d . -o -t2 -safe -space -b -ff -s java -r **/*.class cd .. # remove class files so the diff is clean ${FIND} ${TEMP_DIR} -name '*.class' | xargs rm # diff recursively 

I can run it on Windows using GIT for Windows. Just open the command prompt. Run bash and then open the script.

+2
Jan 24 '17 at 17:55
source share

Use the Java Decompiler to turn the jar file into a source file, and then use WinMerge for comparison.

You should consult the copyright owner of the source code to make sure this is normal.

+1
Oct. 06 2018-10-10T00:
source share
0
06 Oct 2018-10-10T00:
source share

Try http://www.osjava.org/jardiff/ - the tool is old and the list of dependencies is large. From the docs, it seems worth a try.

0
Oct 06 2018-10-10T00:
source share

use java decompiler and decompile all .class files and save all files as a project structure.

then use meld diff viewer and compare them as folders.

0
Jan 19 '16 at 8:11
source share



All Articles