question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

keep getting error "automatic module cannot be used with jlink"

See original GitHub issue

My pom.xml

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.moditect</groupId>
                <artifactId>moditect-maven-plugin</artifactId>
                <version>1.0.0.Beta2</version>
                <executions>
                    <execution>
                        <id>create-runtime-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>create-runtime-image</goal>
                        </goals>
                        <configuration>
                            <modulePath>
                                <path>${project.build.directory}/modules</path>
                            </modulePath>
                            <modules>
                                <module>org.reflections</module>
                                <module>org.jnativehook</module>
                            </modules>
                            <baseJdk>version=11,vendor=openjdk,platform=windows-x64</baseJdk>
                            <launcher>
                                <name>hackstyle</name>
                                <module>hackstyle.HackStyle</module>
                            </launcher>
                            <outputDirectory>
                                ${project.build.directory}/jlink-image
                            </outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-module-infos</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>add-module-info</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/modules</outputDirectory>
                            <modules>
                                <module>
                                    <artifact>
                                        <groupId>org.reflections</groupId>
                                        <artifactId>reflections</artifactId>
                                        <version>0.9.11</version>
                                    </artifact>
                                    <additionalDependencies>
                                        <dependency>
                                            <groupId>javax.activation</groupId>
                                            <artifactId>activation</artifactId>
                                            <version>1.1.1</version>
                                        </dependency>
                                    </additionalDependencies>
                                    <moduleInfoSource>
                                        module reflections {
                                        exports org.reflections;
                                        }
                                    </moduleInfoSource>
                                </module>
                                <module>
                                    <artifact>
                                        <groupId>com.1stleg</groupId>
                                        <artifactId>jnativehook</artifactId>
                                        <version>2.1.0</version>
                                    </artifact>
                                    <moduleInfoSource>
                                        module jnativehook {
                                        exports org.jnativehook;
                                        }
                                    </moduleInfoSource>
                                </module>
                            </modules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <configuration>
                    <mainClass>hackstyle.HackStyle</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.1stleg/jnativehook -->
        <dependency>
            <groupId>com.1stleg</groupId>
            <artifactId>jnativehook</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15.0.1</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime -->
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.0-b170127.1453</version>
        </dependency>
    </dependencies>

my module-info.java

module hackstyle {
    requires javafx.controls;
    requires jnativehook;
    requires reflections;
    requires java.xml.bind;
    requires java.desktop;
    requires java.logging;

    opens hackstyle.scripts to java.xml.bind;
    exports hackstyle;
}

reflections and jnativehook are automatic modules I added add-module-info and create-runtime-image goals trying to fix it but I keep getting "Error: automatic module cannot be used with jlink: reflections from … " when I remove these dependencies from <dependencies> tag I get errors saying reflections is not a library… Did I miss a step?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
aalmiraycommented, May 13, 2021

@seanidzenga Ah yes, I missed that one.

0reactions
seanidzengacommented, May 13, 2021

@aalmiray Is the add-module-info goal not for adding module descriptors to dependencies?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java 11 JLink getting error: automatic module cannot be used ...
I'm trying to add a JDBC connector module to my project with Java 11. I downloaded the MSSqlServer JDBC driver 7.2 for Java...
Read more >
Error: automatic module cannot be used with jlink - YouTube
jpackage -t exe --name Jlink - Error --description "Youtube Tutorial" --app-version 1.0 --input out/artifacts/Packaging_jar --dest C:\Desktop ...
Read more >
automatic module cannot be used with jlink
However, jlink cannot work with automatic modules. The typical way to solve this problem is to convert the non-modular jars to explicit modules,...
Read more >
Jlink and Automatic Modules : r/java - Reddit
However, as you may know, jlink does not work with automatic modules. There are a couple of work around ranging from update the...
Read more >
65787 – POI can't be used with jlink because of dependencies ...
1.jar, SparseBitSet-1.2.jar] Now it fails here Error: automatic module cannot be used with jlink: org.apache.commons.collections4 I investigated ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found