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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With