1

My application needs access to a class that is not exported, com.sun.webkit.network.CookieManager, so, when compiling it I added this option:

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

The full maven-compiler-plugin config looks like this:

<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>

It compiles just fine. If I remove the option I get this error:

[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]

so, it does look like the option it does it's job. The problem comes when I jlink the project, which I do with this command line:

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

everything seems to work, but when I try to run it, I get this error:

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

What else am I missing to gain access to that class?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • You are using JavaFX internal class so you need --add-export at both compile-time and run-time. The script/launcher generated by jlink does not know to do this. Can you just eliminate your dependency on this JavaFX internal class? – Alan Bateman Jul 06 '18 at 13:13
  • @AlanBateman: no, because JavaFX doesn't let you access WebKit cookies. How do you add the option to the `jlink` generated script? – Pablo Fernandez Jul 06 '18 at 13:27
  • I don't know anything about WebKit cookies but you should at least look into if setting your own CookieManager will work. The jlink tool doesn't have any support for adding --add-exports into the generated launcher script. – Alan Bateman Jul 06 '18 at 15:20

0 Answers0