Guides for SE student projects »

Working with JAR files

Java applications are typically delivered as JAR (short for Java Archive) files.

Running JAR files

Not all JAR files are executable. Some may be just a library that you you reuse in your own application.

While some executable JAR files can be launched simply by double-clicking, the fool-proof way to run a jar file is to use the java -jar command e.g., java -jar foo.jar launches the foo.jar file.

You can download the Collate-TUI.jar from and run it using the commandjava -jar Collate-TUI.jar command. It's usage is given here.

Fat JAR files

A normal JAR file contains only the classes and resources that you created for your app. If you app has dependencies (i.e., third party libraries that your app depends on), the JAR file will not work unless the person running the JAR file also has those dependencies in their computer. This is not ideal.

A fat JAR (aka uber JAR) file solves the above problem by including all the dependencies inside the JAR file itself (which makes the JAR file bigger than usual, hence the term fat).

Creating JAR files with Intellij IDEA

Creating a JAR file in Intellij - A video by Artur Spirin:

If your app uses third-party libraries, you are recommended to create a fat jar file (see the Fat JAR files section) using Gradle instead, as explained Creating JAR files with Gradle section.

Although JUnit is a third-party library, you need not package it into a fat JAR file because JUnit is used only in the test code, not in the application code.

But if you use JavaFX, you need to create package it into a fat JAR.

Creating JAR files with Gradle

If you are using Gradle in your project, you can use it to create a JAR file as given in the panel below.

(Although JUnit as test classes are not pacakged into the JAR file).