A Jar file is a 'Java ARchive', a single file collection of all your Java class and resources. They can be run by double clicking on them which makes them very convenient and user friendly. Below is how to make them!
This is a simple text file that says which of your (possibly many) class files contains your main() function.
Main-Class: Hello
In the above, we are saying that the Hello.class contains our main() function, this will probably need changing for your program. Save this as Manifest.txt in the same folder as all of your class files.
To keep things simple and because I cannot remember the options for the jar command, I put the following in a batch file called 'makejar.bat':
javac *.java jar cfmv myapp.jar Manifest.txt *.class
The first line compiles all the Java files in folder.
The next line runs the jar command that collects all the class files and the Manifest above and creates 'myapp.jar'.
The options we give the jar command are:
c = Create a new archive.
f = We are giving a filename for the Jar file.
m = We are using a Manifest file.
v = Verbose output so we can see what it is doing!
If your java program has resources such as images, you can include them too using something like the following:
javac *.java jar cfmv myapp.jar Manifest.txt *.class gifs\*.gif
This will include all gif images in the 'gifs' folder. Note that your program may need tweaking to be able to read them from the Jar file, usually something like:
Image img = ImageIO.read(getClass().getResource("gifs/mypic.gif"));
Usually my makejar.bat file is more like the following, the first line removes all class files in case I have any strays which are no longer relevant, the pause at the end is so I can just double click on the script to run it and the script output does not vanish.
del *.class javac *.java jar cfmv myapp.jar Manifest.txt *.class pause
All being well, you should have a single easy to share Jar file you can just double click to run!
Updated (27/08/2026)