17

I have this classical issue: Using JavaFX 11 with OpenJDK 11 together with Eclipse IDE.

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

I have OpenJDK 11.0.2

dell@dell-pc:~$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
dell@dell-pc:~$ 

And I also have JavaFX 11 SDK. By the way! I'm using Lubuntu Linux 18.10 if you wonder. enter image description here

Then I have included the .jar files from the JavaFX 11 SDK in Eclipse IDE into a library package.

enter image description here

Then I have included this library package into my JAdaptiveMPC project. enter image description here

I get no error in my code syntax, but still, I cannot compile my project. enter image description here

Do you know why? I got the same error if I import all those .jar files from Maven instead of download the JavaFX SDK and import it into a library.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Control</groupId>
  <artifactId>JAdaptiveMPC</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx</artifactId>
        <version>13-ea+5</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-base</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-swing</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-web</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-media</artifactId>
        <version>13-ea+5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>13-ea+5</version>
    </dependency>
  </dependencies>
</project>

Continue

I have added this in the Run Configuration

enter image description here

And then I try to run enter image description here

Still errors.

euraad
  • 2,467
  • 5
  • 30
  • 51
  • Duplicated of [IntelliJ IDEA - Error: JavaFX runtime components are missing, and are required to run this application](https://stackoverflow.com/questions/52906773/intellij-idea-error-javafx-runtime-components-are-missing-and-are-required-t/): If you run your project as a Java Application, you need to add the VM arguments as well. See https://openjfx.io/openjfx-docs/#IDE-Eclipse (non-modular from IDE). If you use Maven, see the Maven section too. – José Pereda Apr 19 '19 at 10:34
  • I have done that now. Still errors. I don't know why. @JoséPereda – euraad Apr 19 '19 at 11:00
  • 1
    Errors: nothing to do with JavaFX "11", but with JavaFX itself and FXML: your path to the FXML file is wrong. Just refer to the root of the resources folder, like `getResources("/se/danielmartensson/controller/gui.fxml")`. As an aside, code is preferred over screenshots when posting a question. – José Pereda Apr 19 '19 at 11:08
  • Now it's working @JoséPereda Very good. I know that code is perferred over screen shorts, but for beginners that doesn't know how to fix this issue, screen shots are more valuable than code. – euraad Apr 19 '19 at 11:23
  • Daniel, if we cannot test the code, it is quite impossible to help you. Please, do not provide in the future images with code. – aironman Nov 20 '21 at 12:56

4 Answers4

25

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.

Datz
  • 3,156
  • 3
  • 22
  • 50
Reizo
  • 1,374
  • 12
  • 17
  • Hello! Thanks for your answer. But I have done that. Se my updated question. – euraad Apr 19 '19 at 10:57
  • @Heretic sorry, I've checked your post more carefully. You're obviously calling `FXMLLoader.setLocation​(URL)`, but apparently your resource (`\JAdaptiveMPC...\gui.fxml`) cannot be found. So check if your location is correct and `Main.class.getResource(...)` does not return `null`. – Reizo Apr 19 '19 at 11:27
  • @Reizo can you please explain how to: "add the JavaFX modules with VM arguments" as you stated in your answer. I'm experiencing this same issue and have been unsuccessful thus far in correcting it. Thank you – Trixie the Cat Feb 14 '20 at 22:56
  • 1
    @TrixietheCat You have to pass the given arguments when launching your program with `java`. Usually your IDE does that under the hood and lets you configure what arguments to pass to the VM. Either see [this](https://stackoverflow.com/questions/5891123/specifying-jvm-arguments-when-calling-a-jar-file) example or look for how to *specify vm arguments in Eclipse/IntelliJ/...*. – Reizo Feb 15 '20 at 14:02
1

The question is old but this how it did work for me in intellij(linux) :

1- go to run -> edit configurations

2- add the path in VM Options :

--module-path yourpath/lib --add-modules javafx.controls,javafx.fxml

1

enter image description here

In eclipse I selected this MODULE PATH option from the dropdown and it worked for me - I didnt need the vm agruments. Make sure the JavaFx Jars are added in the ModulePath under Dependencies Tab (Eclipse >> Project >> Configurations)

Abdeali Chandanwala
  • 8,449
  • 6
  • 31
  • 45
-1

I was working on Eclipse. For me, running the class with the below VM arguments worked:

-p C:\<your_path>\javafx-sdk-11\lib --add-modules javafx.controls,javafx.base,javafx.fxml,javafx.graphics,javafx.media,javafx.web --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED --add-exports javafx.base/com.sun.javafx.event=ALL-UNNAMED
-Djava.library.path="C:\<your_path>\javafx-sdk-11\bin"
ouflak
  • 2,458
  • 10
  • 44
  • 49