Results 1 to 7 of 7
  1. #1
    JunkerMartin is offline Member
    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0

    Default Difference between jar file created with the jar utility and the zip utility

    I have also posted this in the "Java Software"-column. I'm not sure where exactly to place it, but Java-Software was definitely the wrong place! Unfortunately I couldn't move it, so I copied the whole stuff here.


    For training purposes I created a jar file with the zip-utility. I edited the MANIFEST.MF-file and added it as well to the archive. But this gave me a "Invalid or corrupt jarfile" as I was told when I tried to start it with "java -jar ...". The I did the same with the jar-utility. This worked fine. The exploded versions of the jars don't show any difference.
    This is the Ant I used to create both of this archives:
    Java Code:
    	<!-- pack to repository.jar by zip -->
    	<target name="jarRepository" depends="compileRepository">
    	 	<zip zipfile="${generate.dir}/repository.jar" >
    	 		 <fileset dir="${build.classes.dir}" includes="repository/**"/>
    	 		 <fileset dir="${repository}"        includes="META-INF/**"/>
    	   </zip>
    	  </target>
    	
    	<!-- pack to repository.jar by jar -->
    	<target name="jar2Repository" depends="compileRepository">
    	 	<jar jarfile="${generate.dir}/repository2.jar" >
    	 		 <fileset dir="${build.classes.dir}" includes="repository/**"/>
    	   </jar>
    	</target>
    The content of the zipped jarfile is:
    0 Fri Feb 01 12:18:40 CET 2013 META-INF/
    102 Fri Feb 01 12:03:30 CET 2013 META-INF/MANIFEST-MF
    0 Fri Feb 01 12:16:46 CET 2013 repository/
    1263 Thu Jan 31 11:07:58 CET 2013 repository/Activator.java
    0 Thu Jan 31 09:38:50 CET 2013 repository/impl/
    3356 Thu Jan 31 11:52:46 CET 2013 repository/impl/XMLRepositoryService.java
    467 Fri Feb 01 12:03:08 CET 2013 repository/MANIFEST.TXT
    0 Thu Jan 31 12:00:02 CET 2013 repository/META-INF/
    102 Fri Feb 01 12:03:30 CET 2013 repository/META-INF/MANIFEST-MF
    1408 Thu Jan 31 11:46:18 CET 2013 repository/Node.java
    3 Fri Feb 01 08:27:22 CET 2013 repository/packageinfo
    131 Thu Jan 31 09:22:48 CET 2013 repository/RepositoryService.java


    The content of the "jared" jarfile is:
    0 Fri Feb 01 12:04:02 CET 2013 META-INF/
    106 Fri Feb 01 12:04:00 CET 2013 META-INF/MANIFEST.MF
    0 Fri Feb 01 12:04:02 CET 2013 repository/
    0 Fri Feb 01 12:04:02 CET 2013 repository/impl/
    1610 Fri Feb 01 12:04:02 CET 2013 repository/Activator.class
    2713 Fri Feb 01 12:04:02 CET 2013 repository/Node.class
    251 Fri Feb 01 12:04:02 CET 2013 repository/RepositoryService.class
    4911 Fri Feb 01 12:04:02 CET 2013 repository/impl/XMLRepositoryService.class


    The content of the MAINIFEST.MF is in both cases:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.3
    Created-By: 1.6.0_38-b05 (Sun Microsystems Inc.)
    Any idea what might be wrong?

    brgds,
    Ulrich

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Difference between jar file created with the jar utility and the zip utility

    You've zipped the *.java files, not the compiled *.class files.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default Re: Difference between jar file created with the jar utility and the zip utility

    Those files are completely different ... the zipped version contains .java source files while the other one contains compiled .class files; the first version contains more entries; they can't be compared.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default Re: Difference between jar file created with the jar utility and the zip utility

    I deleted your other post.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    JunkerMartin is offline Member
    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0

    Default Re: Difference between jar file created with the jar utility and the zip utility

    Sorry, I tried this much with different parameters. At last I displayed one created with a false the wrong jarfile here. This is the correct one.
    0 Fri Feb 01 16:23:38 CET 2013 repository/
    0 Fri Feb 01 16:23:38 CET 2013 repository/impl/
    1610 Fri Feb 01 16:23:38 CET 2013 repository/Activator.class
    2713 Fri Feb 01 16:23:38 CET 2013 repository/Node.class
    251 Fri Feb 01 16:23:38 CET 2013 repository/RepositoryService.class
    4911 Fri Feb 01 16:23:38 CET 2013 repository/impl/XMLRepositoryService.class
    0 Thu Jan 31 12:00:02 CET 2013 META-INF/
    102 Fri Feb 01 12:03:30 CET 2013 META-INF/MANIFEST-MF
    Sorry for the confusion. As you can see in the Ant-xml; the both of the tasks use the same directory to build the archive.
    When executing the archive with the sources it ends with message "Failed to Main-Class manifest attribute from .."

    brgds,
    Ulrich




    Quote Originally Posted by JosAH View Post
    Those files are completely different ... the zipped version contains .java source files while the other one contains compiled .class files; the first version contains more entries; they can't be compared.

    kind regards,

    Jos

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,802
    Rep Power
    19

    Default Re: Difference between jar file created with the jar utility and the zip utility

    From the docs.
    "
    Ant has been offering the encoding attribute of the zip and unzip task as a way to explicitly specify the encoding to use (or expect) since Ant 1.4. It defaults to the platform's default encoding for zip and UTF-8 for jar and other jar-like tasks (war, ear, ...) as well as the unzip family of tasks.
    "
    So, could be an encoding issue. If that's a Win platform it'll be encoded in that Win encoding whose name I've forgotten.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    JunkerMartin is offline Member
    Join Date
    Feb 2013
    Posts
    6
    Rep Power
    0

    Default Re: Difference between jar file created with the jar utility and the zip utility

    It's solved now. The problem was a typing error in the filename of the manifest-file. I had spelled it "MANIFEST-MF" but must read "MANIFEST.MF".
    Thanks.

Similar Threads

  1. Calling a method in a utility class
    By TMobotron in forum New To Java
    Replies: 2
    Last Post: 09-17-2010, 06:39 AM
  2. XML compare utility
    By JMayura in forum Advanced Java
    Replies: 0
    Last Post: 06-08-2010, 01:05 PM
  3. Replies: 0
    Last Post: 04-16-2008, 10:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •