tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Articles > Java > Basics > How to create Java Executable JAR

How to create Java Executable JAR 

The following example shows creating an executable JAR file in Java. First create a simple standalone java application, for instance a simple Swing UI application.

File Name  :  
package com.btc;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;

public class ExeJARApplication {

  public static void main (String [] args) {
    JFrame frame = new JFrame("My Application");
    frame.getContentPane().add(new JButton("Click Me"));

Compile and run the application for sanity.

javac -d .
java com.btc.ExeJARApplication
Create a manifest file manifest.txt with Main-Class attribute. Ensure to enter a new line at the end of manifest file. Otherwise some systems may throw failed to load Main-Class error.
Main-Class: com.btc.ExeJARApplication

Create an executable JAR using jar command from the console (Ensure to include JDK_HOME\bin in Path environment variable).
jar cvfm [jar-file] [manifest-file] [dirs/files]
jar cvfm test.jar manifest.txt com
Run the executable JAR from the console or from "Open with" windows dialog.
java -jar test.jar
It gives the following output,


bl  br