18

I've followed a tutorial precisely and I can't seem to get it to work. The tutorial is under JavaFX and Intellij Non-modular from IDE sections: https://openjfx.io/openjfx-docs/#install-java

Here is the error message I receive when trying to run the default Intellij Idea JavaFX project:

"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" --module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3\lib\idea_rt.jar=53491:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Users\jonat\IdeaProjects\Tawe-Lib FX\out\production\Tawe-Lib FX;C:\Program Files\Java\javafx-sdk-11.0.1\lib\src.zip;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx-swt.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.web.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.base.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.fxml.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.media.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.swing.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.controls.jar;C:\Program Files\Java\javafx-sdk-11.0.1\lib\javafx.graphics.jar" sample.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.base not found

Process finished with exit code 1

This makes little sense to me as I can see javafx.base under lib on the sidebar: enter image description here

The path leading to jdk-11.0.1 and javafx-sdk-11.0.1:

C:\Program Files\Java

Java is installed:

C:\Users\jonat>java --version
openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

JAVA_HOME variable (mentioned in guide) is set:

C:\Users\jonat>echo %JAVA_HOME%
C:\Program Files\Java\jdk-11.0.1

PATH_TO_FX variable is set:

C:\Users\jonat>echo %PATH_TO_FX%
C:\Program Files\Java\javafx-sdk-11.0.1\lib

I have really no idea where to go from here. I have followed the tutorial precisely, and it does not work. Any help would be greatly appreciated and if you require more info please just drop a comment about it.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
Jonathan Woollett-light
  • 2,813
  • 5
  • 30
  • 58
  • Possible duplicate of [Intellij can't recognize javafx 11 with OpenJDK 11](https://stackoverflow.com/questions/52467561/intellij-cant-recognize-javafx-11-with-openjdk-11) – Pagbo Nov 22 '18 at 16:54
  • What does your `%PATH_TO_FX%` print? Can you run the project from command line? Note also the docs include a tutorial for [IntelliJ](https://openjfx.io/openjfx-docs/#IDE-Intellij), did you check it? – José Pereda Nov 22 '18 at 17:09
  • @JoséPereda Added what `%PATH_TO_FX%` is set to at end of question. – Jonathan Woollett-light Nov 22 '18 at 17:16
  • @JoséPereda I can run the HelloFX example they give in the tutorial however I do not know how I would run this project from command line, and yes I did follow the tutorial for Intellij in the docs. – Jonathan Woollett-light Nov 22 '18 at 17:27
  • The tutorial precisely gives you all the commands you have to use on command line, just open a terminal at your project's root and run them? – José Pereda Nov 22 '18 at 17:29
  • @JoséPereda It gives the commands to run a single file, under the `Run HelloWorld using JavaFX 11` section which I can do. It does not give commands to run an Intellij project. It says `Click Run -> Run... to run the project, now it should work fine.`. – Jonathan Woollett-light Nov 22 '18 at 17:33
  • You have posted you were following the [modular](https://openjfx.io/openjfx-docs/#modular) tutorial, which gives the command line instructions. Anyway, when you run from IntelliJ, you can see the actual command that is executed, so you can copy that and paste it on a terminal, and see what goes wrong. – José Pereda Nov 22 '18 at 17:36
  • @JoséPereda I must apologise, I do not know how I messed that up, I've changed the link to what it should be, I was following the non-modular tutorial. – Jonathan Woollett-light Nov 22 '18 at 17:39
  • I don't really know the difference between modular and non-modular so I just went with what would appear to the the simplest and first presented to me. – Jonathan Woollett-light Nov 22 '18 at 17:41
  • I followed this tutorial and it seems to be easier to follow https://www.cs.rit.edu/~csci142/Resources/setup.html – Teng-pao Yu Oct 29 '20 at 10:43

2 Answers2

32

Based on the posted command line, this is what IntelliJ applies to run your project:

"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" --module-path %PATH_TO_FX% --add-modules=javafx.controls,javafx.fxml

So in the VM options you have set verbatim what the tutorial says:

enter image description here

But you haven't applied your real path for PATH_TO_FX, as it is suggested in the picture inserted after that command in the tutorial:

enter image description here

IntelliJ doesn't resolve that variable and the module path is not set, hence you get the expected error that reveals that the JavaFX modules are not found:

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

Solution

This can be solved in two ways:

  1. Apply your path:

Edit run configurations, and in the VM options add your path:

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

Apply, and run. It should work.

  1. Add the environment variable

You can also set an environment variable. Go to IntelliJ->File->Settings->Appearance & Behavior->Path Variables, and add PATH_TO_FX, with the path to the lib folder:

enter image description here

And then you can use the literals $PATH_TO_FX$ (Does not work for IntelliJ IDEA 2021.1 (Community Edition) on Windows) or ${PATH_TO_FX} in the VM options:

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

Apply, and run.

Note that this is a more permanent solution that can be apply to any other JavaFX project.

MikeSchinkel
  • 4,947
  • 4
  • 38
  • 46
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • 1
    Thank you so much! In my case Intellij had somehow stored an incorrect `PATH_TO_FX` in `IntelliJ->File->Settings->Appearance & Behavior->Path Variables`, which was overriding my system environment variable. Removing the incorrect path fixed my issue. – Guillaume F. May 25 '20 at 15:09
0

The top solution might be working with a simple case, where you did not specify VM options, but sometimes it might be more complicated.

If the top solution is not your case then there is another thing to check: check whether your project root folder contains .iml file of your Module name (check in project structure).

If the .iml is missing then you need to recreate the Module in project structure. You need to recreate the module in project structure, so module will generate and link .iml file.

M22
  • 543
  • 5
  • 10