Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to compare two Java war files

Tags:

java

We built some war files for our web server a while back and have now rebuilt them.

To ensure that nothing has changed (and as a quality check), we tried to compare them using WinMerge. The differences we can see look like they are due to some kind of meta data e.g. the files being built on different dates?

The difference in the lines seems to be consistent e.g.

«d}<

and

³Ze<

The war files are still both the same size.

Is there a way to compare them that strips out the meta data such as date?

like image 727
rbrayb Avatar asked Mar 28 '10 23:03

rbrayb


2 Answers

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.

like image 139
slm Avatar answered Sep 21 '22 03:09

slm


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

like image 23
laher Avatar answered Sep 18 '22 03:09

laher