12

I have a problem with my modular JavaFX application. I created a JavaFX project and added the JavaFX lib and JavaFX modules get recognized. However, I keep getting these error message:

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

Image for the complete setup is attached hereby:

enter image description here

edit:

this is all the errors messages:

/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.library.path=
/home/thenekolite/Documents/JavaTools/javafx-sdk-11.0.1/lib --module-
-path=~/Documents/JavaTools/javafx-sdk-11.0.1/lib 
--add-modules=javafx.controls,javafx.fxml
--add-modules javafx.base,javafx.graphics --add-reads
-javaagent:/home/thenekolite/idea-IU-183.4588.61/
lib/idea_rt.jar=35937:/home/thenekolite/idea-IU-183.4588.61/bin
-Dfile.encoding=UTF-8 -classpath /home/thenekolite/IdeaProjects/
Latihan1/out/production/Latihan1:/home thenekolite/Documents/JavaTools/
javafx-sdk-11.0.1/lib/src.zip:/home/thenekolite/Documents/JavaTools/
javafx-sdk-11.0.1/lib/javafx-swt.jar:/homehome/thenekolite/Documents
/JavaTools/javafx-sdk-11.0.1/lib/javafx.fxml.jar:/home/thenekolite/
Documents/JavaTools/javafx-sdk-11.0.1/libjavafx.media.jar:
/home/thenekolite/Documents/JavaTools/javafx-sdk-11.0.1/lib/
/javafx.swing.jar:/home/thenekolite/Documents/JavaTools/javafx
sdk-11.0.1/lib/javafx.controls.jar:/home/thenekolite/
Documents/JavaTools/javafx-sdk-11.0.1/lib/javafx.graphics.jar
-p /home/thenekolite/Documents/JavaTools/javafx-sdk-11.0.1/lib/
/javafx.base.jar:/home/thenekolite/Documents/
JavaTools/javafx-sdk-11.0.1/lib/javafx.graphics.jar sample.Main

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

I also add the vm options:

enter image description here

but still, i got this error messages.

jewelsea
  • 150,031
  • 14
  • 366
  • 406
rizky ramadhan
  • 157
  • 1
  • 2
  • 6
  • 1
    Hi & welcome to StackOverflow ! Please post code rather than images: it is easier to read and more self-explicit :/ – Cukic0d Dec 15 '18 at 18:22
  • One strange part there in the command line is presence of `--module- -path=~/Documents/JavaTools/javafx-sdk-11.0.1/lib` and `-p` with module path as well, both of which are essentially the same thing. I would have chosen the `-p` specified path not to be there. Along with all this **at the same time all your jars are present in the `-classpath`** which would result in resolving them in an unnamed module. Do check [what all modules are resolved at your application startup](https://stackoverflow.com/questions/48339598/list-the-modules-resolved-during-the-application-startup) – Naman Dec 16 '18 at 13:28
  • I've read the link that you provided to me, but to be honest, I have no idea what should I do right now, I just... don't get it. but, thank you. – rizky ramadhan Dec 19 '18 at 12:52
  • @nullpointer Nevermind, I switch to Java 1.8 and it works! thank you. – rizky ramadhan Dec 19 '18 at 14:58
  • This problem is produced because VM can't find the directory with files required. You can watch this video to correctly configure Java Fx. https://youtu.be/sW4Qlinb0Es – Daniel Pinto S Sep 15 '21 at 16:16
  • @DanielPintoS Is there an English version of this vid? – TheGeeko61 Jan 25 '23 at 12:01

4 Answers4

9

Since you're running as a Non-Modular application from IntelliJ, you would need to ensure adding the VM argument as :

--module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml

You can follow the documentation link as JavaFX and IntelliJ and then Non-modular from IDE for complete setup details.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 2
    Thank you for the answer, but I have following these step and still get error. – rizky ramadhan Dec 16 '18 at 00:51
  • @rizkyramadhan In which case, could you expand the command line as visible in the terminal of IntelliJ and update with the same in the question? (The green highlighted line on your terminal ending with an ellipsis...) – Naman Dec 16 '18 at 03:01
  • I've edited the post and put all the error messages. you know, I tried javafx on my windows 10 and it works perfectly, but I'm not always using windows, for a daily basis, I use Ubuntu 18.04 and it doesn't work. Hmm. – rizky ramadhan Dec 16 '18 at 12:50
  • 1
    For anyone else having issues, this worked for me: as Naman said.. --module-path "C:\Program Files\Java\javafx-sdk-11.0.2\lib" --add-modules=javafx.controls,javafx.fxml – user2078674 Apr 18 '19 at 22:21
  • I've got the same issue, and the problem was with the correct path to the javafx-sdk. In this case, you should update the path after unpacking javafx-sdk to the system very attentively! – Alexandr Kovalenko Sep 23 '20 at 06:42
2

i had the same issue with netbeans, i added the VM options correctly, but i got this error, the solution for my case was to disable Compile on save from project properties -> Build -> Compiling

enter image description here

Hope this will help you in intellij or anyone having the same problem in netbeans.

Diaf Badreddine
  • 550
  • 5
  • 8
0

In IntelliJ, when creating your project, when you do the New > Project wizard, select the "BootstrapFX" dependency.

This adds requires "org.kordamp.bootstrapfx.core;" to your modules-info.java and solved the problem for me in IntelliJ 2021.2.1.

Eddie T
  • 101
  • 5
0

Advice: Use the new project wizard instead of the JavaFX SDK

Don’t use a downloaded JavaFX SDK. Use a build tool, e.g., Maven, to add JavaFX and other dependencies. Use the Create new JavaFX project wizard to generate your project.

The wizard will configure a modular project based on a build tool (maven or gradle).

IMO this is a much easier and better way to create a new project. A project created this way is easier to use, more useful and future-proof as:

  1. The IDE will be able to run the project without having to manually specify command line arguments for the module system. This is because:

    • The IDE can automatically find the required modules from the maven dependencies, so you don't need to specify a --module-path manually.
    • The project contains a module-info.java file so you don't need to --add-modules manually.
  2. The project is self-contained and easier to share:

    • If somebody else wants to use it, they just need to have a standard Java+Maven or Gradle install rather than also finding and downloading a JavaFX SDK.
  3. The project can be easily built using a continuous integration build tool like Jenkins:

    • With a manual SDK dependency setting up Jenkins to build the project would be tricky.
  4. The project can be linked to a runtime using jpackage or jlink.

    • This is because it is a modular application.
  5. You can use the dependency mechanism to add dependencies on other software libraries.

    • Any non-trivial application will need additional dependencies; it is best to manage the JavaFX dependencies and other dependencies the same way IMO.

Troubleshooting steps for using the JavaFX SDK

You have an environmental issue so I can't give a definitive answer, just provide troubleshooting steps so you can repair your environment.

  1. Follow the OpenJFX IO Getting Started steps for Intellij.

    • If you follow the steps exactly, it should work.
  2. If you want to continue using the sdk, put it in a location without spaces, or quote the path when using it.

  3. The Idea UI for VM args is extremely confusing, ensure that you have actually set VM args and not program args. To do that, see this answer to:

  4. Expand the Java execution command which Idea puts in the console pane on execution and copy it as text to add to your question formatted as code.

  5. When you look at the Java execution command, ensure that the module arguments are before your main class name, not after.

  6. Copy the execution command to a command line and try running it there.

  7. When supplying the module path, try using the actual path (properly quoted if that is required), rather than an environment variable.

jewelsea
  • 150,031
  • 14
  • 366
  • 406