Dark Matter
Dark Matter

Reputation: 2311

Issue with Ant build file

I have a java file with the name test1.java with a simplle hello world message.

I have an ANT build script for the creation of the jar file as foll:

<?xml version="1.0" ?>
<project name="test1" default="main">

<target name="main" depends="compile, compress">
<echo>
    Building the .jar file
</echo>
</target>

<target name="compile">
    <javac srcdir="." includeantruntime="false"/>
</target>

<target name="compress">
    <jar jarfile="proj.jar" basedir="." includes="*.class">
            <manifest>
                <attribute name="Main-Class" value="test1"/>
            </manifest>
        </jar>

</target>


</project>

The file is successfully compiled and a ajar file is created.

But when i try to execute the jar as java -jar proj.jar I am getting the foll error: Invalid or corrupt jarfile proj.jar

How can I resolve this issue.

The manifest file's contents are as foll:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.0
Created-By: pap64dev-20071008 (SR6) (IBM Corporation)
Main-Class: test1

Upvotes: 0

Views: 241

Answers (2)

Dark Matter
Dark Matter

Reputation: 2311

Solved it by downgrading to Ant 1.8.4. Ant 1.9 seems to not work with Java 5

Upvotes: 1

kgautron
kgautron

Reputation: 8283

I'd suggest making the "compress" task depend on the "compile" task, because if "compress" is executed first there will be no class file to package.

Also are your sure the name of your main class is really "test1" (by convention class names should start with an uppercase letter).

Upvotes: 0

Related Questions