Jar

Jar packages are Java Archive files. They are commonly used to distribute Java programs and resources. They are sometimes referred to as "Java executables", but not all jar files may be executed.

Jar files use the zip format, so may be extracted using standard zip tools. Because Java software is often distributed via the web, the content is usually compressed, but compression is optional and may be omitted for faster loading. Because zip is a general purpose compression format any kind of file may be included, but platform dependent code should be avoided where possible.

Free or open source projects often include source code in the Jar, in directory /src by convention. This is handly because it allows binary and source distribution in one file, and a simpler downloads page. Source code compresses well so for most projects it will not significently inflate the size of the file. However, because Java object code is hardware-independent, most users (who do not want to modify the software) will never need to compile from source.

A Jar file is executable if the file /META-INF/MANIFEST.MF contains an attribute 'Main-Class', in which case that class is run. Because Jar files run within a virtual machine, the execute file permission bit does not matter.

Jar files have the mime type 'application/x-jar'. By default most desktop environments associate this with a file compression utility such as File Roller or Ark but a more useful setting might be to run the jar file using 'java -jar %f'

Jar files may be created from the command line with the javac command, or from an IDE. For example, in Eclipse select Export -> Export to Jar from the main menu.