Quantcast
Channel: Coffeewithcode.com
Viewing all articles
Browse latest Browse all 40

Ant | How To Create Executable Jar ?

$
0
0

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:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="AntProject" default="makejar" basedir=".">
  3. <target name="makejar" description="Create a jar for the HW project">
  4. <jar jarfile="HelloWorld.jar" includes="*.class" basedir="bin">
  5. <manifest>
  6. <attribute name="Main-Class" value="Main" />
  7. </manifest>
  8. </jar>
  9. </target>
  10. </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.

result


Viewing all articles
Browse latest Browse all 40

Trending Articles