SSJX.CO.UK
Content

Java - Creating Jar Files

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!

Manifest File

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.

The Jar Command

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

Including Resources

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"));

Bonus Tip

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

Final Result

All being well, you should have a single easy to share Jar file you can just double click to run!

Updated (27/08/2026)