Making a JAR with zip

Discussion in 'Java' started by mack, Jun 9, 2004.

  1. mack

    mack Guest

    I want to make a JAR file programmatically from a native app (C++, not
    Java), ultimately using zlib to create the jar.

    As a test, I tried this:

    I took a working JAR file, unzipped it, then rezipped it, and set the
    extension to .jar. Running it tells me it could not find the manifest.

    Unzipping the rezipped file looked exactly the same as the unzipped JAR
    file, however.

    I read somewhere (is it true?) that the manifest must be the first item in a
    jar. So, I used the command line zip command to specify each file. It
    reports that it "added" the files in the order I listed them. Unzipping the
    result appeared to confirm that the manifest was indeed first. Renaming it
    ..jar and running it, again, tells me it could not find the manifest.

    Why aren't my hand-made jar files working?
    What is the difference between a jar and a zip file with a .jar extension?


    Thanks.

    Mack
     
    mack, Jun 9, 2004
    #1
    1. Advertising

  2. mack

    Liz Guest

    "mack" <> wrote in message news:BCEC0BA4.3FC%...
    >
    > I want to make a JAR file programmatically from a native app (C++, not
    > Java), ultimately using zlib to create the jar.
    >
    > As a test, I tried this:
    >
    > I took a working JAR file, unzipped it, then rezipped it, and set the
    > extension to .jar. Running it tells me it could not find the manifest.
    >
    > Unzipping the rezipped file looked exactly the same as the unzipped JAR
    > file, however.
    >
    > I read somewhere (is it true?) that the manifest must be the first item in

    a
    > jar. So, I used the command line zip command to specify each file. It
    > reports that it "added" the files in the order I listed them. Unzipping

    the
    > result appeared to confirm that the manifest was indeed first. Renaming it
    > .jar and running it, again, tells me it could not find the manifest.
    >
    > Why aren't my hand-made jar files working?
    > What is the difference between a jar and a zip file with a .jar extension?
    >
    >
    > Thanks.
    >
    > Mack
    >

    I did something similar to try to reproduce your problem and it works for me
    even though the jar and zip files are different sizes.

    sitting in NewDraw\bin directory

    jar cvfm NewDraw.jar META-INF/MANIFEST.MF *.class
    mkdir save
    cd save
    unzip ..\NewDraw.jar
    zip thing META-INF/MANIFEST.MF *.class
    ren thing.zip NewDraw.jar
    java -jar NewDraw.jar

    application runs fine
     
    Liz, Jun 9, 2004
    #2
    1. Advertising

  3. mack wrote:
    > I read somewhere (is it true?) that the manifest must be the first item in a
    > jar.


    Yes, it is. If you can bring yourself to have a look at the source of
    the constructor of e.g. JarInputStream, you will see for yourself why.

    > So, I used the command line zip command to specify each file. It
    > reports that it "added" the files in the order I listed them. Unzipping the
    > result appeared to confirm that the manifest was indeed first. Renaming it
    > .jar and running it, again, tells me it could not find the manifest.
    >
    > Why aren't my hand-made jar files working?


    Who knows?

    You did place the manifest in the right directory?

    Did you make sure you used the proper file name case and directory name
    case? Java is case sensitive, and Mainfest, mainfest and MANIFEST are
    three different file names as far as Java is concerned.

    Which compression algorithm did you use? Java jars only support deflate
    (early Java version not even that).

    > What is the difference between a jar and a zip file with a .jar extension?


    A jar file is a valid zip file, but not every zip file is a valid jar file.

    /Thomas
     
    Thomas Weidenfeller, Jun 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    587
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,731
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    3,773
    Roedy Green
    Feb 14, 2006
  4. Arnold Peters
    Replies:
    0
    Views:
    670
    Arnold Peters
    Jan 5, 2005
  5. Replies:
    1
    Views:
    97
Loading...

Share This Page