Search code examples
javamavenjavafx

How do I get JavaFx app to recognize a dependency?


My JavaFx app (Java 21, OpenJFX 21) won't recognize a dependency and I don't know why. The dependency is listed as the first entry in my pom's dependencies.

EDIT: the dependency org.mrpc.CommonUtilities is something I wrote and is in my local repository.

My pom.xml file is:

<dependencies>
    <dependency>
        <groupId>org.mrpc</groupId>
        <artifactId>CommonUtilities</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>21</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>21</version>
    </dependency>
    <dependency>
        <groupId>org.controlsfx</groupId>
        <artifactId>controlsfx</artifactId>
        <version>11.1.2</version>
    </dependency>
    <dependency>
        <groupId>com.dlsc.formsfx</groupId>
        <artifactId>formsfx-core</artifactId>
        <version>11.6.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.openjfx</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>net.synedra</groupId>
        <artifactId>validatorfx</artifactId>
        <version>0.4.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.openjfx</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.kordamp.ikonli</groupId>
        <artifactId>ikonli-javafx</artifactId>
        <version>12.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.kordamp.bootstrapfx</groupId>
        <artifactId>bootstrapfx-core</artifactId>
        <version>0.4.0</version>
    </dependency>

My module-info.java file is (the classpath of my dependency is org.mrpc.utilities):

module org.sperbolink.monthlyfinances {
    requires javafx.controls;
    requires javafx.fxml;

    requires org.controlsfx.controls;
    requires com.dlsc.formsfx;
    requires net.synedra.validatorfx;
    requires org.kordamp.ikonli.javafx;
    requires org.kordamp.bootstrapfx.core;
    requires org.mrpc.utilities;

    opens org.sperbolink.monthlyfinances to javafx.fxml;
    exports org.sperbolink.monthlyfinances;
}

A maven dependency:tree shows:

[INFO] org.sperbolink:MonthlyFinances:jar:1.0-SNAPSHOT
[INFO] +- org.mrpc:CommonUtilities:jar:1.0-SNAPSHOT:compile
[INFO] +- org.openjfx:javafx-controls:jar:21:compile
[INFO] |  +- org.openjfx:javafx-controls:jar:win:21:compile
[INFO] |  \- org.openjfx:javafx-graphics:jar:21:compile
[INFO] |     +- org.openjfx:javafx-graphics:jar:win:21:compile
[INFO] |     \- org.openjfx:javafx-base:jar:21:compile
[INFO] |        \- org.openjfx:javafx-base:jar:win:21:compile

And the error from a maven is:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project MonthlyFinances: Compilation failure
[ERROR] /D:/NonGitRepo/MonthlyFinances/src/main/java/module-info.java:[10,22] module not found: org.mrpc.utilities

Solution

  • The error message tells you the error:

    module not found: org.mrpc.utilities
    

    There is no module named org.mrpc.utilities on your module path.

    When you require a module in your project's module-info.java it needs to be a valid module which is on the module path.

    What is the java module name (not package name, jar name or maven artifact name) of the module you wrote, which is contained in the dependency artifact CommonUtilities?

    There are three options:

    1. It will appear in the module-info.java that you created when you wrote the module contained in the CommonUtilities jar.
    2. If there is no module info, then the module name will appear in the Automatic-Module-Name in the META-INF of the CommonUtilities jar.
    3. If there is no automatic name defined in the META-INF, then the assigned automatic module name is CommonUtilities, the same as the jar name.

    To understand more see:

    In general, if you want software that you create to be treated as a full module rather than as an automatic module, then provide that software with an appropriate module-info.java which names the module and use that same module name when you require or otherwise make use of the module.