Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ant jar command gives error: "Building MANIFEST-only jar"

I am using ANT to create a .jar file. Here is my build.xml:

<?xml version="1.0"?>
<project name="stack_overflow" default="info">
    <target name="info">
        <jar destfile="util.jar" includes="com/appl/constants">
            <manifest>
                <attribute name="Main-Class" 
                           value="com.appl.constants.Applicationinfo.class"/>
             </manifest>
        </jar>
    </target>
</project>

When I run ant jar, The util.jar file is generated, but only the manifest.mf is in there.

This is the error I get:

Buildfile: C:\Users\Srikrishna\workspace\SpringExample5\build\build.xml
info:
      [jar] Building MANIFEST-only jar: C:\Users\Srikrishna\workspace\
            SpringExample5\build\${web.dir}\lib\util.jar

BUILD FAILED
C:\Users\Srikrishna\workspace\SpringExample5\build\build.xml:5: 
Could not create almost empty JAR archive (
C:\Users\Srikrishna\workspace\SpringExample5\build\${web.dir}\lib\util.jar 
(The system cannot find the path specified))

Total time: 200 milliseconds

My folder structure is:

src
 |
com.appl.constants
   |
 Applicationinfo.class

Why is nothing getting put into my jar?

like image 352
Krishna Avatar asked Nov 01 '22 16:11

Krishna


1 Answers

You need to specify the basedir attribute to the jar task or use a nested <fileset> to tell the jar task where to look for the classes.

Here is an example build file. Notice in the jar target there is a basedir reference to 'build/classes'

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

    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac srcdir="src" destdir="build/classes"/>
    </target>

    <target name="jar">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/CalculateStats.jar" basedir="build/classes">
            <manifest>
                <attribute name="Main-Class" value="mypackage.CalculateStats"/>
            </manifest>
        </jar>
    </target>

    <target name="run">
        <java jar="build/jar/CalculateStats.jar" fork="true"/>
    </target>

</project>
like image 137
greg-449 Avatar answered Nov 11 '22 14:11

greg-449