简体   繁体   English

Ant构建文件出现问题

[英]Issue with Ant build file

I have a java file with the name test1.java with a simplle hello world message. 我有一个名称为test1.java的Java文件,其中包含一个简单的hello世界消息。

I have an ANT build script for the creation of the jar file as foll: 我有一个用于构建jar文件的ANT构建脚本,如下所示:

<?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 但是,当我尝试以java -jar proj.jar执行jar时,出现以下错误: 无效或损坏的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.8.4来解决。 Ant 1.9 seems to not work with Java 5 Ant 1.9似乎不适用于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. 我建议使“ compress”任务依赖于“ compile”任务,因为如果首先执行“ compress”,将没有要打包的类文件。

Also are your sure the name of your main class is really "test1" (by convention class names should start with an uppercase letter). 您还可以确定主类的名称确实是“ test1”(按照惯例,类名应以大写字母开头)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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