where MainClass is the class with your main method, and package is MainClass's package.
Note you have to compile your .java files to .class files before doing this.
c create new archive
v generate verbose output on standard output
f specify archive file name
e specify application entry point for stand-alone application bundled into an executable jar file
This answer inspired by Powerslave's comment on another answer.
A jar file is simply a file containing a collection of java 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 JarExample {
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). For example,
Manifest-Version: 1.0
Main-Class: JarExample
Place the compiled output class files (JarExample.class,JarExample$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 jexample.mf)
Here it is in one line:
where
MainClass
is the class with yourmain
method, andpackage
isMainClass
's package.Note you have to compile your
.java
files to.class
files before doing this.This answer inspired by Powerslave's comment on another answer.
A jar file is simply a file containing a collection of java 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.Compile your classes. To make a jar, you also need to create a Manifest File (
MANIFEST.MF
). For example,Place the compiled output class files (JarExample.class,JarExample$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 jexample.mf)
It will create executable jarexample.jar.
In Eclipse you can do it simply as follows :