What is a runnable jar file?

Is short it just a zip file, rename into a *.jar file.
It embed all compile java class file required for it execution.

Also it embed a text file call MANIFEST.MF who tell which class to use as entry point of the application (also call Main-Class).


Exemple of /META-INF/MANIFEST.MF file content for a runnable jar:

Main-Class: com.mycompany.MyMainClass

In this example the class com.mycompany.MyMainClass is the entry point.
So it need to implement the function “public static void main(String[] args)”

Let’s look at the source code of dir2server a simple java project.
It use 10 jar libraries as dependancy and it’s entry point is com.doduck.prototype.cli.dir2server
To create a valid runnable jar we need to merge those 10 libraries classes and our classes into a jar file.
We also need to create a MANIFEST.MF who point to our entry point
Main-Class: com.doduck.prototype.cli.dir2server