Java Eclipse: Difference between exporting as a JAR and exporting as a Runnable JAR

The runnable jar contains a MANIFEST.MF file, which defines the Main class to be executed when the jar is run.

Non-runnable jars are just libraries of classes, that can be added to the classpath so that code is reused (it also contains the manifest file, but no main class there)


A runnable jar is a jar file that has an embedded Manifest file that includes the "Main-Class:" declaration. The "Main-Class" must be defined so the java runtime knows which class to call when the jar is "run." If a jar does not include a manifest with the "Main-Class:" it is not considered a "runnable jar" - it is just a library of Java code.

I would guess this is the difference in how Eclipse exports the jar, but not 100% sure.

See this link for more info: http://www.skylit.com/javamethods/faqs/createjar.html


With the standard JAR file, you have to specify the class with the main method on the command line when running the jar. With a runnable JAR, there is a manifest file that will hold that information so you can just type java -jar myRunnable.jar, or simply double click it.

Tags:

Java

Eclipse

Jar