简体   繁体   中英

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

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM