**Creating Executable Jars** A `.jar` file can be used to distribute a Java program. A `.jar` file is essentially a `.zip` file that follows a specific structure. This page describes how to use IntelliJ to create a `.jar` file that can be executed from the command line. # Jar without JavaFX packages (preferred) This approach requires that the computer on which the `.jar` is to be executed already has JavaFX installed and configured. ## Configuring Jar to be Created * Go to **File** -> **Project Structure...** (CTRL+ALT+SHIFT+S) * Select **Artifacts** * Click + * Select **JAR** -> **From modules with dependencies...** * Select the class that contains the `main` method (class that extends `Application`) * Click **OK** * In the **Output Layout** tab, remove all but the last item: + Select **Extracted 'javafx-swf.jar/'** and click - + Remove the remaining entries that begin with **Extracted** leaving just one entry containing **compiled output** ## Creating the Jar * Go to **Build** -> **Build Artifacts** * Select the **Build** action in the pop-up menu * The `.jar` file should be located in a folder in the `out\artifacts` folder of your project ## Running the Jar file You should be able to run the `.jar` file with the following command (from the command line) ```bash java --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml,javafx.swing -jar out\artifacts\WHATEVER_jar\WHATEVER.jar ``` Of course, you'll need to make sure the JavaFX has been installed on the computer and that the `PATH_TO_FX` environment variable has been set appropriately. # Jar with JavaFX packages included If the computer intended to run the program does not have JavaFX installed on it, it is possible to bundle the JavaFX libraries in the `.jar` but it requires more steps and results in a larger file. ## Configuring Jar to be Created * Create the following `Launcher` class ``` public class Launcher { public static void main(String[] args) { // Replace "Main" with the name of the class that extends Application // See https://stackoverflow.com/a/52654791/3956070 for explanation Main.main(args); } } ``` * Go to **File** -> **Project Structure...** (CTRL+ALT+SHIFT+S) * Select **Artifacts** * Click + * Select **JAR** -> **From modules with dependencies...** * Select the class `Launcher` class * Click **OK** * Click the + below the **Output Layout** tab and select **Directory Content** * Select the `C:\bin\Java\javafx-sdk-11.0.1\bin` folder * Click **OK** twice ## Creating the Jar * Go to **Build** -> **Build Artifacts** * Select the **Build** action in the pop-up menu * The `.jar` file should be located in a folder in the `out\artifacts` folder of your project ## Running the Jar file You should be able to run the `.jar` file on any Windows system with Java, but not necessarily JavaFX, installed. Use the following command (from the command line): ```bash java -jar out\artifacts\WHATEVER_jar\WHATEVER.jar ```