Java --add-export не имеет эффекта во время создания ссылок - PullRequest
0 голосов
/ 06 июля 2018

Моему приложению нужен доступ к классу, который не экспортируется, com.sun.webkit.network.CookieManager, поэтому при компиляции я добавил эту опцию:

--add-exports=javafx.web/com.sun.webkit.network=tech.flexpoint.dashman

Полная конфигурация maven-compiler-plugin выглядит следующим образом:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <source>10</source>
        <target>10</target>
        <compilerArgs>
            <arg>--add-exports=javafx.web/com.sun.webkit.network=tech.flexpoint.dashman</arg>
        </compilerArgs>
    </configuration>
    <dependencies> <!-- due to https://stackoverflow.com/questions/49398894/unable-to-compile-simple-java-10-project-with-maven, should be removed later -->
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>6.2</version> <!-- Use newer version of ASM -->
        </dependency>
    </dependencies>
</plugin>

Отлично компилируется. Если я уберу опцию, я получу эту ошибку:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project dashman: Compilation failure: Compilation failure:
[ERROR] /C:/Users/pupeno/Documents/Dashman/code/dashman/src/main/java/tech/flexpoint/dashman/Application.java:[5,22] package com.sun.webkit.network is not visible
[ERROR]   (package com.sun.webkit.network is declared in module javafx.web, which does not export it)
[ERROR] /C:/Users/pupeno/Documents/Dashman/code/dashman/src/main/java/tech/flexpoint/dashman/CookieHack.java:[5,22] package com.sun.webkit.network is not visible
[ERROR]   (package com.sun.webkit.network is declared in module javafx.web, which does not export it)
[ERROR] /C:/Users/pupeno/Documents/Dashman/code/dashman/src/main/java/tech/flexpoint/dashman/controllers/configurator/WebSiteController.java:[5,22] package com.sun.webkit.network is not visible
[ERROR]   (package com.sun.webkit.network is declared in module javafx.web, which does not export it)
[ERROR] -> [Help 1]

так, это выглядит как вариант, который делает свою работу. Проблема возникает, когда я связываю проект, который я делаю с этой командной строкой:

C:\Program Files\Java\jdk-10.0.1\bin\jlink --add-modules tech.flexpoint.dashman --module-path c:\Users\pupeno\.m2\repository\tech\flexpoint\dashmancommon\1.0.0-beta.11;C:\Users\pupeno\Documents\Dashman\code\dashman\target\modules;C:\Users\pupeno\Documents\Dashman\code\dashman\target\classes;C:\Program Files\Java\jdk-10.0.1\jmods --output C:\Users\pupeno\Documents\Dashman\code\dashman\target\jlink-image --launcher Dashman Configurator=tech.flexpoint.dashman/tech.flexpoint.dashman.ConfiguratorApp --ignore-signing-information

кажется, что все работает, но когда я пытаюсь запустить его, я получаю эту ошибку:

Exception in Application start method
java.lang.RuntimeException: Exception in Application start method
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
        at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.IllegalAccessError: class tech.flexpoint.dashman.Application (in module tech.flexpoint.dashman) cannot access class com.sun.webkit.network.CookieManager (in module javafx.web) because module javafx.web does not export com.sun.webkit.network to module tech.flexpoint.dashman
        at tech.flexpoint.dashman/tech.flexpoint.dashman.Application.globalStart(Application.java:162)
        at tech.flexpoint.dashman/tech.flexpoint.dashman.Application.start(Application.java:149)
        at tech.flexpoint.dashman/tech.flexpoint.dashman.ConfiguratorApp.start(ConfiguratorApp.java:51)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
        ... 1 more

Что еще мне не хватает, чтобы получить доступ к этому классу?

...