JavaFX IllegalAccessError on running application

Tags: , ,



I have a JavaFx 14 application running on JDK 14. I created a jlink runtime version that has the only the required modules I need to run the application on both Mac and Wins 10.

I wanted to add a PreLoader to show users while the background processes finish.

I test primarily on Mac OS and then try it on Windows to verify that it still works.

After changing the start from Application.launch(TripsFxApplication.class, args) to LauncherImpl.launchApplication(TripsFxApplication.class, TripsPreloader.class, args), I started seeing this exception trace (scan down).

This is my bat file to run it:

jrebinjava -p javafx-sdk-14.0.2.1lib --add-modules javafx.controls,javafx.base,javafx.fxml,javafx.graphics,javafx.media,javafx.web --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED --add-exports javafx.base/com.sun.javafx.event=ALL-UNNAMED -jar trips.jar

Now the same application works fine on Mac OSX and I see my preloader there, but on Windows 10, I get this error. Is there some extra module that I am missing to add in the bat file above?

Exception trace

jrebinjava -p javafx-sdk-14.0.2.1lib --add-modules javafx.controls,javafx.base,javafx.fxml,javafx.graphics,javafx.media,javafx.web --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED --add-opens javafx.graphics/com.sun.glass.ui=ALL-UNNAMED --add-exports javafx.base/com.sun.javafx.event=ALL-UNNAMED -jar trips.jar
09:49:17,597 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:49:17,597 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:49:17,598 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/Z:/larrymitchell%20On%20My%20Mac/tripsnew/wintripsruntime/trips.jar!/BOOT-INF/classes!/logback.xml]
09:49:17,908 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@73a1e9a9 - URL [jar:file:/Z:/larrymitchell%20On%20My%20Mac/tripsnew/wintripsruntime/trips.jar!/BOOT-INF/classes!/logback.xml] is not of type file
09:49:18,544 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
09:49:18,662 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to INFO
09:49:18,662 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.security.oauth2] to INFO
09:49:18,662 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.integration] to OFF
09:49:18,663 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.oxm] to OFF
09:49:18,663 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.http] to ERROR
09:49:18,663 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.elasticsearch.bootstrap] to ERROR
09:49:18,664 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@71d44a3 - Adding [jar:file:/Z:/larrymitchell%20On%20My%20Mac/tripsnew/wintripsruntime/trips.jar!/BOOT-INF/classes!/logbackbase.xml] to configuration watch list.
09:49:18,664 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@73a1e9a9 - URL [jar:file:/Z:/larrymitchell%20On%20My%20Mac/tripsnew/wintripsruntime/trips.jar!/BOOT-INF/classes!/logbackbase.xml] is not of type file
09:49:18,667 |-INFO in ch.qos.logback.classic.joran.action.JMXConfiguratorAction - begin
09:49:18,832 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word clr with class [org.springframework.boot.logging.logback.ColorConverter]
09:49:18,835 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.catalina.startup.DigesterFactory] to ERROR
09:49:18,835 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.catalina.util.LifecycleBase] to ERROR
09:49:18,835 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.coyote.http11.Http11NioProtocol] to WARN
09:49:18,835 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.sshd.common.util.SecurityUtils] to WARN
09:49:18,835 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.apache.tomcat.util.net.NioSelectorPool] to WARN
09:49:18,835 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate.validator.internal.util.Version] to WARN
09:49:18,835 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:49:18,845 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
09:49:18,858 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:49:19,178 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
09:49:19,246 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
09:49:19,249 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:49:19,300 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@2073621255 - Will use gz compression
09:49:19,303 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@2073621255 - Will use the pattern logs/terranrepublicviewer.log.%d{yyyy-MM-dd}.log for the active file
09:49:19,311 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/terranrepublicviewer.log.%d{yyyy-MM-dd}.log.gz'.
09:49:19,311 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
09:49:19,317 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Mon Oct 05 09:33:15 EDT 2020
09:49:19,325 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1208121709 - Will use gz compression
09:49:19,325 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy@1208121709 - Will use the pattern logs/terranrepublicviewer.log.%d{yyyy-MM-dd}.%i.log for the active file
09:49:19,326 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34123d65 - The date pattern is 'yyyy-MM-dd' from file name pattern 'logs/terranrepublicviewer.log.%d{yyyy-MM-dd}.%i.log.gz'.
09:49:19,326 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34123d65 - Roll-over at midnight.
09:49:19,327 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34123d65 - Setting initial period to Mon Oct 05 09:33:15 EDT 2020
09:49:19,328 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34123d65 - SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
09:49:19,328 |-WARN in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@34123d65 - For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy
09:49:19,336 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: logs/terranrepublicviewer.log
09:49:19,336 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [logs/terranrepublicviewer.log]
09:49:19,339 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to INFO
09:49:19,340 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
09:49:19,341 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
09:49:19,341 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:49:19,341 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@59474f18 - Registering current configuration as safe fallback point

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.IllegalAccessError: class com.teamgannon.trips.TripsSpringBootApplication (in unnamed module @0x639c2c1d) cannot access class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.application to unnamed module @0x639c2c1d
        at com.teamgannon.trips.TripsSpringBootApplication.main(TripsSpringBootApplication.java:32)
        ... 8 more
Z:larrymitchell On My Mactripsnewwintripsruntime>

Answer

ok, I searched around and if you want to use a PreLoader in a JDK 9+ modular environment, then you have to do it this way

 System.setProperty("javafx.preloader", "com.teamgannon.trips.javafxsupport.TripsPreloader");
Application.launch(TripsFxApplication.class, args);
Application will look for the property holding the preloader and insert it correctly. This should be documented better but there you go.


Source: stackoverflow