IntelliJ IDEA - Error: JavaFX runtime components are missing, and are required to run this application
There are similar questions like this or this other one.
Before JavaFX 11, whenever you were calling something JavaFX related, you had all the javafx modules available within the SDK.
But now you have to include the modules/dependencies you need.
Your error says that you are using FXML but it can't be resolved, but you have just added the javafx.controls
module:
--add-modules=javafx.controls
As you can see in the JavaDoc the javafx.controls
module depends on javafx.graphics
and java.base
, but none of those modules includes the FXML classes.
If you need FXML classes like the FXMLLoader
, you need to include javafx.fxml
module:
--module-path="C:\Program Files\Java\javafx-sdk-11\lib" \
--add-modules=javafx.controls,javafx.fxml
The same will apply if you need media or webkit, those have their own modules.
Error: JavaFX runtime components are missing - JavaFX 11 and OpenJDK 11 and Eclipse IDE
Your problem is not compiling the project, but running it.
Since your main
is defined in your Application
-extension, running the project will require JavaFX in your module path on startup.
So either outsource your main
into a class different from your Application
or add the JavaFX modules with VM arguments:
--module-path="<javafx-root>\lib" --add-modules="javafx.base,javafx.controls,javafx.media,…"
See this for some more info.
JavaFX Maven project in IntelliJ. JavaFX runtime components are missing only in IntelliJ. JAR through mvn package executes without issues
This is more a troubleshooting and research guide than an actual fix. Fixes for environmental issues are difficult to provide in a StackOverflow context. However, if you study the information here, it might help you fix your project.
Recommended troubleshooting approach
Use the Intellij new JavaFX project wizard. Ensure that it works in your environment, then gradually add components from your current project into the working project, checking that everything still works after each small addition.
Debugging when executing via the JavaFX maven plugin
I think the above recommendation is the preferred approach, however, you can alternately get the following to work:
run with: mvn clean javafx:run
The need to execute with IntelliJ is to debug the code"
See:
- intellij idea : how to debug a java:fx maven project?
I also think you can just right-click on the maven target for javafx:run
and select Debug. I am not sure, I don't make use of the JavaFX maven plugin.
Creating fat jars for JavaFX applications
the fat jar
This is not a recommended configuration, but if you really must do it, you can review:
- Maven Shade JavaFX runtime components are missing
That answer doesn't discuss getting such a configuration to work in conjunction with an Idea run/debug configuration, so it may not assist you.
If you do continue with a fat jar, I would not advise using a module-info, as you will be running code off the classpath anyway.
Modular versus non-modular JavaFX applications
If you don't use a fat jar, getting all the module dependencies correct for Spring is tricky anyway because Spring is not currently architected to directly support modules well. Spring 6 will be designed to work well with modules, though I think you should be able to get Spring 5 to work if you try hard enough (I have got it to work in the past for some applications).
Alternately you can just have the JavaFX components as modules and run the rest off the classpath. For example, the "Non-modular with Maven" approach at openjfx.io. Note that in that approach, the JDK and JavaFX modules are still loaded as modules off of the module path, it is only Spring your application that is not providing a module-info.java file and running off the classpath.
Creating runtime images for JavaFX applications
I also advise studying:
- these resources for the creation of an appropriate runtime image.
JavaFX runtime components are missing, even though I already have them in my VM options and Modules
Okay, so I found out why this is occurring.
I put the module path and add modules in the program arguments and not in the vm options, which is what is causing the red issue.
Now I am encountering a "Error occurred during initialization of boot layer" issue now.
Related Topics
Why Does Autoreconnect=True Not Seem to Work
Error Message "Unreported Exception Java.Io.Ioexception; Must Be Caught or Declared to Be Thrown"
How to Abort a Thread in a Fast and Clean Way in Java
Meaning of New Class(...){{...}} Initialization Idiom
Which Annotation Should I Use: @Idclass or @Embeddedid
Junit Confusion: Use 'Extends Testcase' or '@Test'
Openjdk Availability for Windows Os
Is This a Bug in Files.Lines(), or am I Misunderstanding Something About Parallel Streams
Change a Method at Runtime via a Hot Swap Mechanism
Log4J Configuration via Jvm Argument(S)
Why Can't We Use '==' to Compare Two Float or Double Numbers
Why Can This Generic Method with a Bound Return Any Type
Does Java Have Buffer Overflows
Java - JPA - @Version Annotation
"Unmappable Character for Encoding" Warning in Java
Where Do I Have to Place the Jdbc Driver for Tomcat's Connection Pool