What happens if you insert a manifest element instead of a manifest property, 
and let ANT dynamically build the manifest file?

        <jar destfile="AntFail/antfail.jar" basedir="AntFail/bin" >
                <manifest>
                        <attribute name="Main-Class" value=" 
com.antfail.AntFail "/>
                </manifest>
        </jar>



-----Original Message-----
From: Marc Benstein [mailto:mbenst...@ultramain.com] 
Sent: Thursday, March 28, 2013 9:59 AM
To: user@ant.apache.org
Subject: Re: Java 5 fails to run jar files created with Ant 1.9.0

On Thu, 2013-03-28 at 05:59 -0600, Stefan Bodewig wrote:
> On 2013-03-28, Marc Benstein wrote:
>
> > Java 5 fails to execute jars created with Ant 1.9.0. Java 6 and 7 work
> > fine to execute the jar.
>
> I assume creating the same jar with Ant 1.8.x works just fne for you.

Correct.

>
> Ant 1.9.0 ships with a zip package that has some enhancements over the
> one in 1.8.x - Zip64 support in particular.  It is possible Ant now
> creates jars by default that Java5 doesn't like.
>
> > The message I am seeing in Java 5 is "Invalid or corrupt jarfile"
>
> Is there any sort of additional information?  You say jar -tf doesn't
> complain.  Do you only get the error when you use java -jar or also when
> you add the jar to the classpath and execute your main class explicitly?

I have found the exact cause. It seems using the manifest attribute in
the jar element causes the jar problem. I have created a simple ant
build.xml to demonstrate. Use Java 5 to run this file.

Here's the output from the build file:

Buildfile: /home/mbenstein/build.xml

create-main:

compile-main:
    [mkdir] Created dir: /home/mbenstein/AntFail/bin
    [javac] Compiling 1 source file to /home/mbenstein/AntFail/bin

jar-main:
      [jar] Building jar: /home/mbenstein/AntFail/antfail.jar

run-jar:
     [java] Invalid or corrupt
jarfile /home/mbenstein/AntFail/antfail.jar
     [java] Java Result: 1

BUILD SUCCESSFUL
Total time: 1 second



-- build.xml --
<?xml version="1.0"?>
<project name="jarfail" default="run-jar">

  <target name="create-main">
    <echo append="no" message="package com.antfail;${line.separator}"
file="AntFail/src/com/antfail/AntFail.java" />
    <echo append="yes" message="public class AntFail { public static
void main(String[] args)
{ System.out.println(System.getProperty(&quot;java.version&quot;)); 
}}${line.separator}" file="AntFail/src/com/antfail/AntFail.java" />
  </target>

  <target name="compile-main" depends="create-main">
    <mkdir dir="AntFail/bin" />
    <javac srcdir="AntFail/src" destdir="AntFail/bin"
includeantruntime="no" />
  </target>

  <target name="jar-main" depends="compile-main">
    <property environment="env" />

    <manifest file="AntFail/MANIFEST.MF">
      <attribute name="Main-Class" value="com.antfail.AntFail" />
    </manifest>

    <jar manifest="AntFail/MANIFEST.MF" destfile="AntFail/antfail.jar"
basedir="AntFail/bin" />
  </target>

  <target name="run-jar" depends="jar-main">
    <java jar="AntFail/antfail.jar" fork="true"/>
  </target>

  <target name="clean">
    <delete dir="AntFail" />
  </target>
</project>

-- End build.xml --


--
Marc Benstein

Ultramain Systems, Inc.
8100 Lang Avenue NE
Albuquerque, NM 87109
USA

TEL 505.828.9000
FAX 505.823.1841
www.ultramain.com

Confidentiality Notice: This email message and any files transmitted with it 
may contain confidential information intended only for the person(s) to whom 
this email is addressed. If you have received this email in error, please 
notify the sender immediately by phone or email and destroy the original 
message without making a copy. Thank you.

Reply via email to