taylorialcom/ Tools

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 with JavaFX packages included (preferred)

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

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); 
    }
}

Creating the Jar

Running the Jar file

You should be able to run the .jar file on any Windows system with Java, but not necessarily JavaFX, installed. Move the .jar file to your project folder (same folder as the src and .iml file). Then use the following command (from the command line):

java -jar WHATEVER.jar

Jar without JavaFX packages

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

Creating the Jar

Running the Jar file

You should be able to run the .jar file on any Windows system with Java and JavaFX installed. Move the .jar file to your project folder (same folder as the src and .iml file). Then use the following command (from the command line):

java —module-path C:\Java\javafx-sdk-19\lib —add-modules javafx.controls,javafx.fxml,javafx.swing -jar WHATEVER.jar

Of course, you’ll need to modify the module path to where you installed JavaFX.