Skip to content

Instantly share code, notes, and snippets.

@stevenliebregt
Last active March 22, 2023 18:09
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save stevenliebregt/bc62a382fc43064136b662ee62172ab3 to your computer and use it in GitHub Desktop.
Save stevenliebregt/bc62a382fc43064136b662ee62172ab3 to your computer and use it in GitHub Desktop.
Tutorial to add JavaFX 11 to Java 11 in Eclipse

How to use JavaFX 11 with Java 11 in Eclipse IDE?

Note!

Be sure you are using Java 11, these methods are specifically written for Java 11 since that's the version where JavaFX became separated.
You can also use the official OpenJFX tutorial to find out how to install and use JavaFX 11.

Downloading JavaFX

Go to either the JavaFX site or directly to the download page and download JavaFX 11 for your OS.

Put the contents of this zip file somewhere on your system, for example in C:\Program Files\C:\Program Files\OpenJFX. If done correctly, this folder now contains a folder with a name along the lines of javafx-sdk-11.

Warning, after I wrote this, JavaFX 11.0.1 came out, so look out for the version number behind the folder

The structure inside the javafx-sdk-11 will look something like this:

/bin/
	(on Windows this will contain some .dll files)
/legal/
	(contains licenses)
/lib/
	(this contains some .jar files)

Using JavaFX in Eclipse

To use JavaFX 11 with Eclipse you will need to do 2 things, add the module path to the VM arguments, and add the libraries to Eclipse.

Adding the libraries to Eclipse

To add the libraries, edit the build path, and add the JavaFX .jar files to the module path, do this by clicking on the Add External JARS button, and selecting all the JavaFX modules. The result will look something like this.

Imgur

After doing this, the JavaFX imports should now be fixed.

To also be able to compile and run the code, you should add the modules to the VM arguments too.

To do so, edit the Run Configurations and go to the Arguments tab. In the VM arguments field, enter the following lines, with the path changed to your actual OpenJFX install location.

--module-path="C:\Program Files\OpenJFX\javafx-sdk-11\lib" --add-modules=javafx.controls,javafx.fxml

If you need other JavaFX modules than controls and fxml, then these should also be added to the same --add-modules line, separated by a comma.

After this, your configuration will look like this.

Imgur

@ChristianScheub
Copy link

Thanks a lot for this nice tutorial :)

Copy link

ghost commented Aug 28, 2020

Is it required to add the VM arguments for every class?

@stevenliebregt
Copy link
Author

@Amma2003 No, if I remember correctly, it is per project

Copy link

ghost commented Aug 30, 2020

Thanks

@ecochetti
Copy link

Thank you SO MUCH for this tutorial!!! I had such weird errors from installing it through the eclipse marketplace and couldn't find a fix but just doing this worked like a charm!

@paddocc
Copy link

paddocc commented Nov 24, 2020

Any way to have the class path reference Jar files inside the same folder? Rather than starting from C;/ ?

@OrangoMango
Copy link

Can you share in some way the jar containing all javafx files?

@swastiksanath
Copy link

Not working for me, Am getting this error Illegal char <:> at index 2: =C:\Program Files\Oracle\JavaFX 2.0 SDK\rt\lib--add-modules=
Please help

@mihai-daniel
Copy link

This solved my problem, as no Java FX element was recognised in Eclipse. Thank you so much!

@youssefsha
Copy link

Thnk U a lot !!!

@foffor
Copy link

foffor commented Feb 4, 2022

I've followed these steps but system still cannot see the following import: import javafx.fxml.FXMLLoader;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment