Ant jar command gives an error: "Creating banner MANIFEST-only"
I use 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 util.jar , but only the .mf manifest is present 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:
src | com.appl.constants | Applicationinfo.class Why doesn't anything get into my jar?
+4
1 answer
You need to specify the basedir attribute for the jar task or use the nested < fileset> to tell the jar task where to look for classes.
Here is an example build file. Note that in the jar target there is a link to the link '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> +2