pauliamgiant
pauliamgiant

Reputation: 13

JavaFX, JLink/JPackage Module issue - adding Libraries "Error occurred during initialization of boot layer java.lang.module.FindException"

IDE: IntelliJ. Trying to use JavaFX for the first time with some additional libraries, and with an installable package - (c/o JLink/JPackage) Have followed directions from OpenJFX for a Modular Project from IDE and can get this to work no problem. https://openjfx.io/openjfx-docs/

Adding libraries though I am just getting this error: "Error occurred during initialization of boot layer java.lang.module.FindException: Module eu.hansolo.medusa not found, required by ModuleName"

Have read a number of similar threads on this error but no joy here specifically.

Have tried adding adding to VM on run configuration ie:
--module-path ${PATH_TO_FX}:mods/production --add-modules javafx.controls,javafx.fxml,eu.hansolo.medusa -
still getting "Error occurred during initialization of boot layer java.lang.module.FindException: Module eu.hansolo.medusa not found"

However.. If I delete the "module-info.java" file.. I can run the application in IntelliJ no problem.. however.. I then can't use JLink to make the custom runtime image.

Any advice or pointers to reading I can do would be greatly appreciated and many thanks in advance.

Upvotes: 1

Views: 2458

Answers (1)

matt
matt

Reputation: 12346

So the issue appears to be that you haven't added Medusa to your module path. The way I accomplished this is by using maven.

I added the dependencies to my pom file and created a module-info.java and everything seemed to work.

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <groupId>org.example</groupId>
    <artifactId>MavenFxied</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics</artifactId>
            <version>14.0.1</version>
        </dependency>
        <dependency>
            <groupId>eu.hansolo</groupId>
            <artifactId>Medusa</artifactId>
            <version>11.5</version>
        </dependency>
    </dependencies>

</project>

module-info.java

module mavenfxied {
    requires javafx.controls;
    requires eu.hansolo.medusa;
    exports example;
}

I made an example class to test it out.

Main.java

package example;

import eu.hansolo.medusa.Gauge;
import eu.hansolo.medusa.GaugeBuilder;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Main extends Application {

    public void start(Stage stage) throws Exception {
        StackPane pane = new StackPane();
        Gauge g = GaugeBuilder.create()
                .skinType(Gauge.SkinType.SPACE_X)
                .animated(true)
                .decimals(0)
                .title("SpaceX")
                .unit("km/h")
                .maxValue(30000)
                .threshold(25000)
                .build();
        pane.getChildren().add(g);
        Scene scene = new Scene(pane);
        stage.setScene(scene);
        stage.show();
    }
}

If you aren't using maven, then the solution proposed in the comments of adding the jar file to a location on the module-path might be the only way.

Upvotes: 1

Related Questions