rbrayb
rbrayb

Reputation: 46720

Is there a way to compare two Java war files

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?

Upvotes: 11

Views: 50784

Answers (7)

Marcus Junius Brutus
Marcus Junius Brutus

Reputation: 27286

Just use pkgdiff:

pkgdiff a.war b.war

Readily available in Linux, fairly parsable output (you can also check the status code from a bash script). It also generates an awesome HTML report.

Upvotes: 4

slm
slm

Reputation: 16416

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.

Upvotes: 10

Lewis B
Lewis B

Reputation: 59

You can configure WinMerge to compare zip files (and by the way, .WAR files), if you install the 7zip plugin of WinMerge. Keep in mind that is not very easy to install, you must install the plugin, it is made of .dll and must be extracted in a folder.... Honestly I dont remember how I did it. I believed at the end I used the standalone installer ooption and use 9.20 version of the plugin.

Althoug some times, winmerge tells me there are diferences in .class files, it hightlighs the binary line, but i dont see anydiference. At least you can compare war folder structure at least.

Upvotes: 0

Shanaka Jayalath
Shanaka Jayalath

Reputation: 339

Use "Beyond Compare" free trial... (or buy it) I think it is the only tool that can do that.

Upvotes: 0

Venkat Sadasivam
Venkat Sadasivam

Reputation: 1464

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.

Upvotes: 6

laher
laher

Reputation: 9110

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

Upvotes: 8

Kris
Kris

Reputation: 14458

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.

Upvotes: 7

Related Questions