How to make an executeable jar

Delivering desktop application developed in java, its very interactive that you give your software in a executable jar, rather giving .bat files (running java <main>.class)

To do that, try these steps.

First, jar all of your class files and let Java create it’s own manifest. First, make sure you are in the directory of your class files:

jar cvf MyJarFile.jar *.class

You would replace MyJarFile.jar with whatever you want the jar file to be named. Then, create a regular text file with this:

Main-Class: MainClass

Make sure you hit enter at the end. The file has to end with a carriage return. Say you name the text file ManifestUpdate.txt. Make sure you save it in the same directory as all your class files.

Then do this:

jar umf ManifestFile.txt MyJarFile.jar

This essentially updates the current Manifest file in your .jar file with the contents of the text file you created.

Again, go through the JAR tutorial. It will help you out a lot!

Related Posts Plugin for WordPress, Blogger...
This entry was posted in Java and tagged .

One thought on “How to make an executeable jar

  1. People should consider using Ant to build their software. The task has a manifest attribute:

    <jar destfile="${dist}/lib/app.jar"

    and a manifest subtask:

    <jar destfile="test.jar" basedir=".">
    <include name="build"/>
    <attribute name="Built-By" value="${}"/>
    <attribute name="Main-Class" value="com.acme.widget.MailService"/>
    <section name="common/class1.class">
    <attribute name="Sealed" value="false"/>

    In fact, people should always build Java applications withAnt (or Maven).

Leave a Reply

Your email address will not be published. Required fields are marked *