Hi All,
I'm having trouble using Archive::Zip to write a file that is then readable by the jar program (Sun JDK 1.5.0_10).

I want to take a JAR created elsewhere and modify a file inside it with perl an write it back out. However, after modification and writing out with Archive::Zip, the jar program gives an error when reading the contents. Here are the stripped down steps:

  1. Create foo.jar: 'jar cf foo.jar hello.txt'
  2. Run the following code:
  3. use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $az_foo = Archive::Zip->new('foo.jar'); unless ($az_foo->writeToFileNamed('bar.jar') == AZ_OK ) { die 'write error'; } my $az_bar = Archive::Zip->new(); unless ( $az_bar->read('bar.jar') == AZ_OK ) { die 'bad bar bad!' }
    ** This gives no errors or warnings.**
  4. Now run 'jar tf bar.jar'. This gives the error:
    java.util.zip.ZipException: only DEFLATED entries can have EXT descrip +tor at java.util.zip.ZipInputStream.readLOC(ZipInputStream.java:250) at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:7 +3) at sun.tools.jar.Main.list(Main.java:735) at sun.tools.jar.Main.run(Main.java:191) at sun.tools.jar.Main.main(Main.java:903)
I've done a lot of research and investigation without many fruits. Using 'zipinfo.pl' from the Archive::Zip examples/ did get me some clues:
  1. bar.jar is 2 bytes smaller than foo.jar
  2. The directory member for META-INF/ has a few different parameters between the two JAR's:
    • compressionMethod: foo.jar=8, bar.jar=0
    • desiredCompressionMethod: foo.jar=8, bar.jar=0
    • desiredCompressionLevel: foo.jar=-1, bar.jar=0
  3. I've tried manually setting these parameters on the member before writing out, but the values remain the same.

It seems to me the 'META-INF/' directory member is actually expected to be deflated by the jar program - doesn't make sense. I thought I'd ask those wiser than myself before contacting the owner on this one...maybe there is something simple I can do. Cheers and beers.

20070813 Janitored by Corion: Changed PRE tags to P tags, as per Writeup Formatting Tips


In reply to Archive::Zip Problem: Zip versus Jar file formats by sblanton

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.