Getting JavaFX Working in Windoze and Linux

by liu23e

Please direct all complaints to Eric Liu. If you have any problems, please fill out this google form.

Downloading the SDK

You can get the SDK at this link.

Download the file corresponding to your operating system. The version should be the latest one available. Please see the table below for the row with which you should download from:

Your computer's type Column values on Gluon website
Windows (typical) Windows, x64, SDK
Linux Linux, x64, SDK

Windows setup

After downloading the .zip archive, extract it to the folder where you want to install the JavaFX SDK.

Navigate to the location of the directory (named javafx-sdk-[version number]), and enter the /lib directory.

The objective here is to get the path of the /lib directory. You may do this manually.

Alternatively, you can get the path following the above screenshot of Windows Explorer. This will move the path into your clipboard.

One time run instructions

Now that the SDK is installed, you may run code at any time using the following commands, given you have the path from the previous steps.

            > javac --module-path [INSERT_PATH_HERE] --add-modules javafx.controls [CLASS_NAME].java
            > java --module-path [INSERT_PATH_HERE] --add-modules javafx.controls [CLASS_NAME]

Insert the path to the /lib folder of the JavaFX SDK on your computer in place of [INSERT_PATH_HERE].

Making things permanent

In order to alleviate the need to type the path to the JavaFX SDK each time, you may add the path to the system environment variables.

On Windows 10, you may do this by searching for "Environment Variables" in the Windows Start menu. Then, click on the "Environment Variables" button in the bottom right corner.

It should look like the above image. You may have different environment variables in your system.

In order to perform this process, select the "New" button below the "System Variables" section.

You may name the variable whatever you wish, but for the sake of this example, it will be named PATH_TO_FX.

This is in accordance to the JavaFX website, and will be used for the remainder of this page.

For the value of the environment variable, enter the path to the /lib folder of the JavaFX SDK on your computer.

Please ensure that you select "OK" on all menus so that the variable's value is retained.

You may verify using the terminal whether the environment is present. All methods should return the correct path set in the previous steps.

Terminal Command Expected output
PowerShell Get-Item Env:PATH_TO_FX No error text
Command Prompt echo %PATH_TO_FX% Non-null output
Bash echo $PATH_TO_FX Non-null output

The commands used to run a Java class using JavaFX are quite similar to before:

This section is not tested. Please fill out this google form if something goes wrong.
Terminal Commands
PowerShell javac --module-path Get-Item Env:PATH_TO_FX --add-modules javafx.controls [CLASS_NAME].java
java --module-path Get-Item Env:PATH_TO_FX --add-modules javafx.controls [CLASS_NAME]
Command Prompt javac --module-path %PATH_TO_FX% --add-modules javafx.controls [CLASS_NAME].java
java --module-path %PATH_TO_FX% --add-modules javafx.controls [CLASS_NAME]
Bash javac --module-path $PATH_TO_FX --add-modules javafx.controls [CLASS_NAME].java
java --module-path $PATH_TO_FX --add-modules javafx.controls [CLASS_NAME]

*nix Setup

For macOS, please follow the instructions at this link

Linux Setup

If your computer runs Linux, please prefer your package manager over this.

For Arch and Arch-based distributions, see this AUR entry.

For Debian-based distributions, you may find the package openjfk in apt.

One-time install instructions

If you choose not to install via a package manager, these instructions will guide through the same process as for Windows, with platform appropriate changes.

In theory, this should work for macOS as well, but it has not been tested.

After downloading the appropriate .zip file, extract this archive into the folder of your choice.

Any responsible folder is okay for this task, however, please keep in mind the path as it will be used in the next steps.

In this example, I will extract it to my Applications folder, at /home/[my user]/Applications. This can be done using the following command:

        > unzip -d [INSERT_PATH_HERE]

In place of [INSERT_PATH_HERE], insert the path to the /lib folder of the SDK.

The filename, in this case, may differ due to your platform.

Now that you have the SDK installed, you may reference the path to the /lib folder of the SDK, and run the JavaFX application.

The commands to do so are:

        > javac --module-path [INSERT_PATH_HERE] --add-modules javafx.controls [CLASS_NAME].java
        > java --module-path [INSERT_PATH_HERE] --add-modules javafx.controls [CLASS_NAME]

The end result should look similar to this:

Making things permanent

As a shortcut, you may alleviate needing to type the entire command by adding your SDK path to your system PATH, or by setting an alias for it in your shell resource file.