Gaetano Sette
Gaetano Sette

Reputation: 1

I have an error while I run throught cli interface: JavaFX runtime components are missing, and are required to run this application

I have developed a javafx application with Intellij. The problem is that when I run the program through Intellij there aren't problem about it while if I run through command line or just double-clicking, the program doesn't run

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

Upvotes: 0

Views: 79

Answers (1)

VGR
VGR

Reputation: 44404

As of Java 11, JavaFX is not part of the JDK. You have to add it yourself.

You also have to create a separate class to hold your main method. It can be any class which doesn’t extend a JavaFX class. This is because JavaFX loads native libraries, and the native library path isn’t available during the stage where Java is starting up the main class.

If your program is a module, you can just add the JavaFX SDK to your module path:

java -p /home/sette/projects/example/build:/opt/javafx-jmods-12 \
    -m com.example.myapp/com.example.myapp.Startup

(If you’re running on Windows, replace / with \, and replace : with ;.)

If your program is not a module, you need to include both the .jar files and the native libraries:

java -cp /home/sette/projects/example/build/MyApp.jar:/opt/javafx-sdk-12/lib/"*" \
    -Djava.library.path=/opt/javafx-sdk-12/lib \
    com.example.myapp.Startup

Again, the main class (Startup in the above examples) must not extend javafx.application.Application. It can and should call Application.launch.

Upvotes: 1

Related Questions