Step 1. Download JavaFX
Go to https://gluonhq.com/products/javafx/ and download the appropriate SDK for your operating system. Make sure you download the SDK and make sure you choose the correct operating system and architecture for your computer. More than likely, you’ll be downloading one of the outlined options below.
This will install a .zip
file. Unzip this file and put the resulting folder in a memorable place, such as your /Documents
folder. We’ll need this later.
Step 2. Create a User Library in Eclipse
- Open up Eclipse and go to Preferences
- You should be able to get to Preferences from Eclipse > Preferences or Window > Preferences
- Go to Java > Build Path > User Libraries
- Now click New…
- Name it JavaFX and click Ok
- With JavaFX highlighted, click Add External JARs…
- Select all the
.jar
files from the/lib/
folder of the unzipped JavaFX folder we saved earlier.
- Click Open and your new User Library should look something like this:
- Click Apply and Close to save your new User Library
Step 3. Create a JRE clone with the required VM arguments
- Go back to Preferences in Eclipse
- Go to Java > Installed JREs
- Select your default JRE and click Duplicate
- Copy this line if you’re on Windows
--module-path "\path\to\javafx-sdk-17\lib" --add-modules javafx.controls,javafx.fxml
- Copy this line if you’re on Mac or Linux
--module-path /path/to/javafx-sdk-17/lib --add-modules javafx.controls,javafx.fxml
- Important: Make sure you replace the
/path/to/javafx-sdk-17/lib
with the path to where you placed your unzipped JavaFX folder from before. You will want the entire path all the way to the /lib/ folder. For instance, mine on a Mac looks like this:--module-path /Users/pragways/Documents/javafx-sdk-17.0.1/lib --add-modules javafx.controls,javafx.fxml
- Paste that line in the Default VM arguments: field
- Rename the JRE name: field to something memorable, such as javafx-jre-15
- Click Add External JARs…
- Select all the
.jar
files from the/lib/
folder of the unzipped JavaFX folder we saved earlier and then click Open
- Your JRE Definition window should now look something like this
- Click Finish
Step 4. Create a new project with your new JRE
Now whenever you want to create a new JavaFX project, it will be a lot quicker and easier!
All you need to do is make sure you select Use a project specific JRE when creating a new project, and then select your new JavaFX specific JRE that you just created.