How to make an executable Jar file in Java

Mausam Singh
1 min readNov 22, 2020

Jar file

JAVA EXECUTABLE FILE

A jar file is simply a file containing a collection of java class files.

To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.

public class JavaClassName{    public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
// your logic here
}
});
}
}

Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF).

Manifest-Version: 1.0
Main-Class: JavaClassName

Place the compiled output class files (JavaClassName.class,JavaClassName$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as manifest.mf).

jar helloworld JavaClassName.jar manifest.mf *.class

--

--

Mausam Singh

Aspiring Product Manager | Android Developer | Ex-SDE at Meesho | I believe in writing for self reflection and reading for self development.