122

I'm trying to run the sample JavaFX project using IntelliJ but it fails with the exception :

Error: JavaFX runtime components are missing, and are required to run this application

I have downloaded JDK 11 here : http://jdk.java.net/11/ I have downloaded OpenJFX here : http://jdk.java.net/openjfx/ I'm using : IntelliJ IDEA 2018.2 (Community Edition) Build #IC-182.3684.40, built on July 17, 2018 JRE: 1.8.0_152-release-1248-b8 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

I have created a new JavaFX project in IntelliJ using JDK 11. My JavaFX classes were not known so I have added the OpenJFX library by doing :

  • File -> Project Structure -> Modules -> + -> Library -> Java

I have the OpenJFX added with the 8 jars below "classes" and also the folders below "Sources" and the path to the bin folder under "Native Library Locations".

When I'm building the project, it's good, but impossible to run it.

What am I doing wrong?

Maxoudela
  • 2,091
  • 3
  • 15
  • 23
  • 6
    Have a look at this [getting started](http://docs.gluonhq.com/javafx11/) guide. See all the required configuration to compile and run your sample. Note also that you can add the JavaFX dependencies directly from Maven Central. – José Pereda Jul 23 '18 at 12:59
  • Thanks I've followed it and it' actually working. Pretty odd that I cannot launch it directly from IntelliJ... – Maxoudela Jul 23 '18 at 13:20
  • Good to know. Everything is EA yet, but if you can run modules from your IDE, you should be able to config the project to run it. Did you try it using the pom.xml? – José Pereda Jul 23 '18 at 13:25
  • Yes indeed I've made a Maven Project but impossible to run it through IntelliJ, only from the CommandLine. – Maxoudela Jul 23 '18 at 14:19
  • being on eclipse, with a similar problem (slightly different context): adding both --module-path and --add-module as vm args for the installed jre helped – kleopatra Jul 24 '18 at 08:35
  • @kleopatra What if you put them on the classpath and not on the module path (in a non-modular project)? – user1803551 Sep 01 '18 at 23:17
  • @user1803551 I need them on the module path to tweak the modules (open for internal access) - that's working okay, except for a bug in eclipse that doesn't copy them over correctly to the runtime environment https://bugs.eclipse.org/bugs/show_bug.cgi?id=534572 – kleopatra Sep 02 '18 at 10:35
  • $ sudo apt-get install openjfx – Elliptical view Nov 12 '19 at 01:58
  • 1
    I recently ran into this problem with a Java 17 app in IntelliJ. I noticed that if you make the application modular by adding a module-info file, the problem goes away. – Zach Oct 20 '21 at 17:23

1 Answers1

108

This worked for me:

File >> Project Structure >> Modules >> Dependency >> + (on left-side of window)

clicking the "+" sign will let you designate the directory where you have unpacked JavaFX's "lib" folder.

Scope is Compile (which is the default.) You can then edit this to call it JavaFX by double-clicking on the line.

then in:

Run >> Edit Configurations

Add this line to VM Options:

--module-path /path/to/JavaFX/lib --add-modules=javafx.controls

(oh and don't forget to set the SDK)

LuminousNutria
  • 1,883
  • 2
  • 18
  • 44
Tim V
  • 1,255
  • 1
  • 9
  • 5
  • 10
    JavaFX 11 is no longer bundled with JDK , it builds on top of JDK 11 and is a standalone component. Just see this video on how to integrate them https://www.youtube.com/watch?v=qn2tbftFjno You need to download the stand-alone JavaFx here >>>> https://gluonhq.com/products/javafx/ Cheers – Tonnie Jan 01 '19 at 11:50
  • 1
    @Fanadez the video contains the precise steps infact, kudos! – Zeeng Dec 05 '19 at 12:54
  • 1
    If you use Eclipse, please make sure, to also deacitvate the ()Use the -XstartOnFirstThread argumemt when launching with SWT, otherwise efforts to use JavaFX will not not be proccessed . :) – mZed Dec 26 '19 at 15:28
  • The set-up instructions tell you to use the VM Options line from your answer on the command line. It absolutely did not work for me, but using the NetBeans "Edit Configurations" menu really worked. Thank you! – rocksNwaves Apr 10 '20 at 02:15
  • 17
    `--add-modules=javafx.controls` gave me **java.lang.module.FindException: Module javafx.controls not found** – Lei Yang Sep 16 '20 at 01:19
  • Based on official docs, you also need to add `javafx.fxml` to command args – ryzhman Nov 28 '20 at 13:17
  • *java.lang.module.FindException: Module javafx.controls not found* for me too – Hakanai Dec 23 '20 at 21:34
  • 4
    `--module-path /path/to/JavaFX/lib --add-modules=javafx.controls,javafx.fxml` ..... just add the `javafx.fxml` if you're working with fxml. – Kidus Tekeste Mar 27 '21 at 16:10
  • See my answer at the topic by link in the header https://stackoverflow.com/questions/52467561/intellij-cant-recognize-javafx-11-with-openjdk-11 to make your solution complete, don't forget exports. – WebComer Apr 04 '21 at 12:25