1

I'm trying to make a multi-module maven project. First module would be an JavaFX and the second one would be a SpringBoot, but I'm having problem with the JavaFX.

When I run mvn clean install I get these errors: module not found: javafx.fxml, module not found: javafx.controls, module not found: javafx.graphics

module-info.java:

module example {
    requires javafx.fxml;
    requires javafx.controls;
    requires javafx.graphics;
}

I do have javafx in my pom.xml as seen here:

   <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>11.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>16-ea+5</version>
        </dependency>
    </dependencies>

My application runs without problem, but maven seems to have some kind of problem with javafx.

I use IntelliJ IDEA.

3 Answers3

2

For future references.

Seems like I found out the answer on my own.

The problem was that I forgot to add this

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>15</source>
                    <target>15</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

to my pom.xml

0

Add a third dependecy for javafx-controls or replace javafx-graphics with javafx-controls

mipa
  • 10,369
  • 2
  • 16
  • 35
  • Still no luck, tried replacing and/or adding, nothing works. – Lukáš Hasprún Dec 20 '20 at 20:54
  • You also have different version numbers in your dependencies (11.0.1 vs 16-ea+5) which is also no good idea. – mipa Dec 20 '20 at 21:01
  • Oh, didn't know, since Intellij generated it for me I though it was ok. Tried changing every dependency to version 15 with no luck at all. – Lukáš Hasprún Dec 21 '20 at 08:13
  • 2
    All parts of JavaFX should have the same version number and 16-ea+5 would have been perfectly ok. Just follow the documentation closely with your setup: https://openjfx.io/openjfx-docs/ Then you can be sure that JavaFX will work correctly. – mipa Dec 21 '20 at 13:41
0

I was working in IntelliJ IDEA and also encountered this problem. NOTHING worked, not one single solution I found on the internet, but then I took a look into File > Project Structure > Problems and there I saw the following line (alongside 3 others, in my case)

Library Maven: org.openjfx:javafx-controls:linux:16 is not used [Fix]

So I pressed on [Fix] and one of the options was "Add to Dependencies", which, upon selecting, resulted in the following message:

Library `Maven: org.openjfx:javafx-controls:linux:16` will be added to the selected modules:

and a list consisting of one module named after the name of my project.

I hit "OK" and then "OK" and all in all, there was one significant change.

It turned out that I was missing the following line:

<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:linux:16" level="project" />

and 3 more, very similar ones with javafx-fxml, javafx-base, and javafx-graphics in the file ProjectName.iml, where ProjectName was the name of my project.

I am not an expert, so I do not know what I have just done, but hopefully this helps a poor soul who finds themselves in the same situation I had.

Maurycyt
  • 676
  • 3
  • 19