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!
http://java.sun.com/docs/books/tutorial/deployment/jar/

You May Also Like

1 Comment

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


    <jar destfile="${dist}/lib/app.jar"
    basedir="${build}/classes"
    excludes="**/Test.class"
    manifest="${extras}/MANIFEST.MF"
    />

    and a manifest subtask:


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

    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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.