ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Welsh, Armand" <>
Subject RE: Java 5 fails to run jar files created with Ant 1.9.0
Date Thu, 28 Mar 2013 18:53:34 GMT
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" >
    			<attribute name="Main-Class" value=" com.antfail.AntFail "/>

-----Original Message-----
From: Marc Benstein [] 
Sent: Thursday, March 28, 2013 9:59 AM
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.


> 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


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

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

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

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/" />
    <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/" />

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

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

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

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

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

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

-- End build.xml --

Marc Benstein

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

TEL 505.828.9000
FAX 505.823.1841

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.
View raw message