Is there a way to compare two Java war files

WAR files are basically Zip files. Why not extract the contents and compare each file in turn? This avoids any meta-data that is a part of the WAR file. You can also figure out what the differences actually are if any are discovered.


It should be easier if you unzip them first and then compare folders.

In Windows you could just use the 'jar' executable which comes with the jdk

jar -xvf xxxx.war

Then you can use WinMerge to compare the 2 folders.

Hope this helps


you can use eclipse to compare jar/war files. http://www.javalobby.org/java/forums/m91839415.html

The link does not mention war file. I'm using Indigo, it seems eclipse only support jar comparison hence I have to rename the war extension to jar to get eclipse to do the structural comparison.


I generally use an approach like this and run 2 unzip commands and diff the output as required. For example I need to compare 2 Java WAR files.

$ sdiff --width 160 \
   <(unzip -l -v my_num1.war | cut -c 1-9,59-,49-57 | sort -k3) \
   <(unzip -l -v my_num2.war | cut -c 1-9,59-,49-57 | sort -k3)

Resulting in output like so:

--------          -------                                                       --------          -------
Archive:                                                                        Archive:
-------- -------- ----                                                          -------- -------- ----
48619281          130 files                                                   | 51043693          130 files
    1116 060ccc56 index.jsp                                                         1116 060ccc56 index.jsp
       0 00000000 META-INF/                                                            0 00000000 META-INF/
     155 b50f41aa META-INF/MANIFEST.MF                                        |      155 701f1623 META-INF/MANIFEST.MF
 Length   CRC-32  Name                                                           Length   CRC-32  Name
    1179 b42096f1 version.jsp                                                       1179 b42096f1 version.jsp
       0 00000000 WEB-INF/                                                             0 00000000 WEB-INF/
       0 00000000 WEB-INF/classes/                                                     0 00000000 WEB-INF/classes/
       0 00000000 WEB-INF/classes/com/                                                 0 00000000 WEB-INF/classes/com/
...
...

I prefer this approach since it doesn't require space to uncompress the files and then compare them.

Tags:

Java