Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: automatic module cannot be used with jlink: com.sun.jna #7

Closed
titinko opened this issue Dec 6, 2020 · 6 comments
Closed

Error: automatic module cannot be used with jlink: com.sun.jna #7

titinko opened this issue Dec 6, 2020 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@titinko
Copy link

titinko commented Dec 6, 2020

Does NSMenuFX currently not work with jlink?

I tried importing the library in my pom.xml:

<dependency>
      <groupId>de.jangassen</groupId>
      <artifactId>nsmenufx</artifactId>
      <version>3.0.1</version>
</dependency>

then added the nsmenufx module to module-info.java:

open module com.utsusynth.utsu {
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.media;
    requires java.desktop;
    requires org.apache.commons.io;
    requires jdk.charsets;
    requires jdk.localedata;
    requires com.google.guice;
    requires nsmenufx;

    exports com.utsusynth.utsu;
}

The library works fine when I run it locally (mvn javafx:run) but when I try to deploy with jlink (mvn javafx:jlink) I get the does-not-work-with-jlink error:

Error: automatic module cannot be used with jlink: com.sun.jna

I had assumed from codecentric#36 that this fork would be jlink-compatible, but is it not there quite yet? Or is there another dependency/module I'm not adding properly? Thanks!

@0x4a616e
Copy link
Owner

0x4a616e commented Dec 6, 2020

Hi @titinko thank you for your report. I actually haven't tried jlink yet but I think there will be a solution. I probably have to rework the module-info a bit using jdeps.

@0x4a616e
Copy link
Owner

0x4a616e commented Dec 6, 2020

Moditect might help here too, I'll have to give it a try.

@0x4a616e
Copy link
Owner

0x4a616e commented Dec 6, 2020

So, there are a few aspects to this issue. First, the good news: JNA is the only non-modular dependency and they already added JPMS support for the next release (java-native-access/jna#1237 and https://github.com/java-native-access/jna/blob/master/CHANGES.md), so we only need to find a temporary solution until this will be available. Unfortunately, I could not find any details on when this will be release, however all planned features seem to be completed.

Next, we can use moditect to add a module-info.java file to jna using something like this:

<plugin>
    <groupId>org.moditect</groupId>
    <artifactId>moditect-maven-plugin</artifactId>
    <version>1.0.0.RC1</version>
    <executions>
        <execution>
            <id>add-module-infos</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>add-module-info</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/modules</outputDirectory>
                <overwriteExistingFiles>true</overwriteExistingFiles>
                <modules>
                    <module>
                        <artifact>
                            <groupId>net.java.dev.jna</groupId>
                            <artifactId>jna</artifactId>
                            <version>5.6.0</version>
                        </artifact>
                        <moduleInfoSource>
                            module com.sun.jna {
                                exports com.sun.jna;
                                exports com.sun.jna.ptr;
                                exports com.sun.jna.win32;
                                exports com.sun.jna.internal to com.sun.jna.platform;
                                requires java.logging;
                                opens com.sun.jna.darwin;
                            }
                        </moduleInfoSource>
                    </module>
                </modules>
            </configuration>
        </execution>
    </executions>
</plugin>

The problem however is that it is currently not so simple to use this with the javafx-maven-plugin as there is currently just no option to add something to the module path (see openjfx/javafx-maven-plugin#104 or openjfx/javafx-maven-plugin#110).

If someone has a good idea on how to add the moditect-modded module to the module path for jlink, please let me know! If I find any other solution, i'll let you know.

I also tried to use the "regular" (non-javafx) jlink maven plugin (https://maven.apache.org/plugins/maven-jlink-plugin/) but couldn't really get this to work due to

[ERROR] Error: automatic module cannot be used with jlink: javafx.graphicsEmpty from file:///Users/jan/.m2/repository/org/openjfx/javafx-graphics/11/javafx-graphics-11.jar

Any ideas maybe on how to work around that?

@0x4a616e 0x4a616e added the enhancement New feature or request label Dec 6, 2020
@0x4a616e 0x4a616e self-assigned this Dec 6, 2020
@0x4a616e
Copy link
Owner

I think we're close: java-native-access/jna@be5eec5

@0x4a616e
Copy link
Owner

The day has finally come! if you update to the latest version 3.1.0 you should be able to successfully run mvn javafx:jlink. I gave it a try in the samples project and everything worked well. It would be great if you could confirm if things are now working for you as well so we can close this issue :)

@titinko
Copy link
Author

titinko commented Feb 18, 2021

I tried again and the library builds perfectly now, so I've added it to my project and now have the Preferences menu item in the right place. Thank you so much!

@titinko titinko closed this as completed Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants