Comparing two .jar files

前端 未结 11 1382
灰色年华
灰色年华 2020-12-04 06:57

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

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

相关标签:
11条回答
  • 2020-12-04 07:17

    Please try http://www.osjava.org/jardiff/ - tool is old and the dependency list is large. From the docs, it looks like worth trying.

    0 讨论(0)
  • 2020-12-04 07:23

    Here's an aparently free tool http://www.extradata.com/products/jarc/

    0 讨论(0)
  • 2020-12-04 07:28

    Here is my script to do 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 
        ${DIFF} ${EXT_DIR1} ${EXT_DIR2}
    

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

    0 讨论(0)
  • 2020-12-04 07:29

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

    then use meld diff viewer and compare as folders ..

    0 讨论(0)
  • 2020-12-04 07:30

    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.

    0 讨论(0)
提交回复
热议问题