5

I just created a new JavaFX project in intelliJ with an openjdk 11 and I've downloaded the last openjfx library on their website.

Here is what I did :

I've added to Run/Debug VM options : --module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml VM Options

I've added a new variable env PATH_TO_FX : PATH_TO_FX=%programfiles%\Java\javafx-sdk-11\lib

So it compiles good but it fails at runtime :

Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found

Does anyone know what am I missing here ?

PS : I've followed this link https://openjfx.io/openjfx-docs/#install-javafx

EDIT :

Should I have onpenjfx libraries here ? classpath

kleopatra
  • 51,061
  • 28
  • 99
  • 211
Gilles
  • 229
  • 1
  • 3
  • 11
  • Please check if runtime classpath contains javafx.controls module. – y.bedrov Oct 19 '18 at 09:45
  • I guess yes -classpath "C:\IdeaProjects\RandomStudent\out\production\RandomStudent;C:\Program Files\Java\javafx-sdk-11\lib\src.zip;C:\Program Files\Java\javafx-sdk-11\lib\javafx-swt.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.web.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.base.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.fxml.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.media.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.swing.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.controls.jar;C:\Program Files\Java\javafx-sdk-11\lib\javafx.graphics.jar" sample.Main – Gilles Oct 19 '18 at 13:32
  • It may be easier to include it as a dependency via gradle or maven than by using it like in 10 and 9. – Hypnic Jerk Oct 19 '18 at 14:51
  • the fx libraries must be on the modulepath, both at compile time and at runtime (no idea how to do that in idea ;) – kleopatra Oct 19 '18 at 15:17
  • Have you checked this [question](https://stackoverflow.com/questions/52467561/intellij-cant-recognize-javafx-11-with-openjdk-11)? Is your project modular? Maybe you can also check this other [question](https://stackoverflow.com/questions/51843208/running-javafx-sample-on-jdk-11-with-openjfx-11-jmods-on-module-path). – José Pereda Oct 19 '18 at 16:04
  • My project is not modular. I wanted to do it the sdk way but I'll try with gradle or Maven... @kleopatra I will have a look in that direction just to be sure – Gilles Oct 19 '18 at 17:39
  • Can you try with a hardcoded path to your JavaFX lib instead of the variable env in the VM options? – José Pereda Oct 19 '18 at 21:02

2 Answers2

5

This error is shown since the Java 11 launcher checks if the main class extends javafx.application.Application. If that is the case, it is required to have the javafx.graphics module on the module-path.

  1. Add VM options

To solve the issue, click on Run -> Edit Configurations... and add these VM options:

--module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml

Note that the default project created by IntelliJ uses FXML, so javafx.fxml is required along with javafx.controls. If your project uses other modules, you will need to add them as well. enter image description here

Click apply and close the dialog.

  1. Run the project

Click Run -> Run... to run the project, now it should work fine.

liuyez123
  • 464
  • 4
  • 6
  • I checked many answers but this one was precise and to the point, screenshot is always big plus. I must say, since they've separated the JFX and JDK, setting the environment itself is a trickier task now. – Stack2Heap Jun 22 '20 at 17:25
3

To solve the issue, click on Run -> Edit Configurations... and add modify the path variable as follows:

--module-path ${PATH_TO_FX} --add-modules=javafx.controls,javafx.fxml