In this article I am going to describe about how to create executable jar file using ant file.
For this I am using a java project with an ant file.
In my previous post I have detailed how to create ant hello world ant project.
I will use the same project here as well.
To create an executable jar file one need to edit projectBuilder.xml file.
So new projectBuilder.xml will looks like as below:
- <?xml version="1.0" encoding="UTF-8"?>
- <project name="AntProject" default="makejar" basedir=".">
- <target name="makejar" description="Create a jar for the HW project">
- <jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin">
- <manifest>
- <attribute name="Main-Class" value="Main" />
- </manifest>
- </jar>
- </target>
- </project>
Now run this ant file right click and run as Ant build.
Here I added a manifest tag with Main-class in jar tag.
This will set Main-Class in MANIFEST.MF
One can see the Manidest.MF by double click on HelloWorld.jar–>META-INF–>Manifest.MF As below:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_18-b07 (Sun Microsystems Inc.)
Main-Class: Main
One can also execute HelloWorld.jar on the command line as below.
Image may be NSFW.
Clik here to view.
Clik here to view.
