1

I'm creating a JavaFX project for the first time, and I'm having a bit of trouble with exporting and deploying the project. Following this tutorial, I tried using jlink, but ran into an error:

Error: automatic module cannot be used with jlink: json from file:///C:/Users/owner/.m2/repository/org/json/json/20180130/json-20180130.jar
[ERROR] Command execution failed.

I am using the org.json:json:20180130 artifact as a dependency in the project, and that seems to be the cause of this error. I've looked at similar questions to mine on SO already as well as some other online resources. But I am having a lot of trouble understanding the solutions to them, as I'm only a beginner to this.

I've read about adding a module descriptor, and generating a module-info using the command line. But I'm not sure how to do that.

Here is my module-info.java currently (youdolist is my project):

module youdolist {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.media;
    requires json;

    opens youdolist to javafx.fxml;
    exports youdolist;
}

And here is my pom.xml:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>youdolist</groupId>
    <artifactId>youdolist</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180130</version>
            <scope>compile</scope>
        </dependency>


    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>youdolist.Main</mainClass>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>
deduper
  • 1,944
  • 9
  • 22
  • 3
    I have added an [answer to a similar question](https://stackoverflow.com/a/63627730/1746118). To help you understand, since `org.json:json:20180130` dependency in your code brings in a JAR which does not have explicit module declaration(`module-info` class), if it is found on the modulepath, it would be treated as an [automatic module](http://openjdk.java.net/projects/jigsaw/spec/sotms/#automatic-modules). That is where the problem stems from as `jlink` does not support automatic modules. – Naman Aug 28 '20 at 05:08
  • Thanks, so if I were to use jdeps in my specific situation to generate module-info, what exactly would I need to do/type? Also, does it matter that I already have a module-info with the javafx stuff that wasn't automatic modules? – Sankeeth Ganeswaran Aug 28 '20 at 15:22
  • 1
    If you were to use `jdeps` in your case, you would have to perform commands over the JAR file for `org.json:json`. The links shared further have relevant commands. What you already have is the explicit module declaration for your current project that you might be looking to use `jlink` for. – Naman Aug 28 '20 at 16:26
  • From what I understand, the jdeps command in the terminal is $ jdeps --generate-module-info , but what exactly do I put in the output-location? Sorry for asking so much, I appreciate your help. – Sankeeth Ganeswaran Aug 29 '20 at 00:58
  • 1
    This tutorial https://github.com/dlemmermann/JPackageScriptFX explains how you can package your app without all this module system crazyness. – mipa Aug 29 '20 at 09:08

0 Answers0