Comparing two .jar files

前端 未结 11 1512
灰色年华
灰色年华 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: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.

提交回复
热议问题