2 Replies Latest reply: Jan 28, 2010 10:36 AM by 843804 RSS

    comparing a .jar to a directory

    843804
      I am trying to find a way to verify that everything from a folder successfully copied into a .jar. Is there a simple (automated) way to do this? I would like to do so without expanding the .jar.

      When looking for answers, I see that I can continuously verify a signed .jar over time, but this isn't exactly what I want to do; I just want to verify that my .jar contains all of the files from my original directory when I create it.

      When I create a .tar, I can run "tar --diff --file=stuff.tar originalStuff" ("originalStuff" being the folder I created the stuff.tar from) and the program will notify me of any differences. I want to do this same thing with a .jar.

      If I expand the .jar and then compare two directories/folders, say stuffVersion1 to stuffVersion2, I can just run a (recursive) "diff," but this won't work when one of the items to compare is a .jar and the other is a directory.


      Things I've tried that don't work:
      1. I ran "jar tf stuff.jar," piped the list to a text file, then compared that text file to a text file of an "ls" command on the original folder. (This doesn't work because file order and relative paths aren't in the same between "ls" and "jar tf," so "diff" thinks the files have hundreds of differences.)

      2. I downloaded programs that compare two versions of a .jar. The two I have tried are Jar Compare, and jar-diff.
      Comparing a .jar to a folder causes a file not found exception <access is denied>.
      --These programs are meant to compare two .jars, not a folder and a .jar?
      -- another problem may be that the files in my .jar are mostly word files, not .class or .java files?

      3. Keeping a text file containing a list of checksums for all of the files in the directory and then using "md5sum --check" to compare the files to their sums. (again, this works only if I expand the .jar first.)
        • 1. Re: comparing a .jar to a directory
          793415
          mona.b wrote:
          I am trying to find a way to verify that everything from a folder successfully copied into a .jar. Is there a simple (automated) way to do this? ...
          Ant. I do not know if it offers anything in particular that can check that a Jar has the same contents as a directory, but it can create the Jar in the first place, and once the correct files are specified, it will stamp out a complete Jar whenever needed.
          • 2. Re: comparing a .jar to a directory
            843804
            Thanks for the response!

            As far as I can tell so far, Ant doesn't do exactly what I want. I am glad to know about it since I may have a use for it in the future. The checksum function appears to only work on files or directories, meaning that the .jar would still need to be unzipped.

            For now a friend of mine suggested a solution that works, although all it does is check file names, not checksums or file size; basically I pipe "ls" and "jar tf" to text files and then compare those txt files:

            # Get file list, extract column 8, remove directories (path with a trailing /), sort, save to file
            jar tvf stuff.jar | awk '{print $8}' | grep "[^/]$" | sort >list1.txt

            # Find all files (skip directories) in folder directory, sort, save to a file
            find originalStuff/* -type f | sort >../list2.txt

            # Compare files
            diff list1.txt list2.txt