• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing war files

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any way by which we can compare two war files using java.

Kind Regards,
Joshua
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is a command called jar -tvf <file name>. This command will list all files in jar file alongwith folder structure.

You can probably run this command for both jar files from your java code and than used try comparing output of both of them.

By this you can compare two jar files are same in terms of contents or not. but if you want to check if 2 jar files are having same versions for all files in it than this solution won't work
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use the Checksum interface (Alder32, CRC32) classes. You would read the files and pass them to the Checksum. The Checksum will return the same number if the files are the same, however it won't tell you where they are different. You could do all this in a couple lines of code.

Here is an example of this from the always useful Java Almanac:

http://www.exampledepot.com/egs/java.util.zip/ChecksumFile.html?l=rel
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but the test fails in the following situation:

Creating two war files with the same content using jar cvf ....
Is there any way round for this problem.

Kind Regards,
Joshua.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks, but the test fails in the following situation:

Creating two war files with the same content using jar cvf ....


That sounds strange, because it should work. Can you show us the code you wrote to implement this, so we can take a look at it?
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The output is :
Original -------- 1390004477
Copy -------- 2950613217
Are the files equal ? true
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you even looking at the last 128 bytes of the two files to decide whether the method should return true fo false? I'd think that the method should return true only if the two checksums are identical.

Are the two war files actually identical?
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the war files are identical.
Please ignore the byte comparison(I was testing some other thing...). The main point is that checksum does not return same long value for identical war files.

Kind Regards,
Joshua
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure the files are the same? Remember it just takes just one difference for them to be different. For example the data of a file in the zipfile. Even if the file in the zip file is the same if its date is off the file is off.
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for the replies.

I found the root cause of the problem - the ant task generates the war files with some minor difference every time it is build.

Kind Regards,
Joshua
 
reply
    Bookmark Topic Watch Topic
  • New Topic