JavaFX运行应用程序时出现IllegalAccessError。

huangapple go评论68阅读模式
英文:

JavaFX IllegalAccessError on running application

问题

以下是翻译好的内容:

我有一个在JDK 14上运行的JavaFx 14应用程序。我创建了一个jlink运行时版本,其中只包含我在Mac和Windows 10上运行应用程序所需的必要模块。

我想添加一个预加载器,在后台处理完成之前向用户显示。

我主要在Mac OS上进行测试,然后在Windows上尝试以验证它仍然可以工作。

在将启动方式从 Application.launch(TripsFxApplication.class, args) 更改为 LauncherImpl.launchApplication(TripsFxApplication.class, TripsPreloader.class, args) 后,我开始看到以下异常跟踪(向下滚动)。

这是我用来运行它的批处理文件:

jre\bin\java -p javafx-sdk-14.0.2.1\lib --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

现在同样的应用程序在Mac OSX上正常工作,我在那里看到了我的预加载器,但在Windows 10上,我收到了这个错误。在上面的批处理文件中,是否有一些额外的模块我忘记添加了?

异常跟踪

jre\bin\java -p javafx-sdk-14.0.2.1\lib --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]
...
(以下为日志记录的其他信息,此处省略)
...
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 Mac\tripsnew\wintripsruntime>

英文:

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:

jre\bin\java -p javafx-sdk-14.0.2.1\lib --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

<!-- language: none -->

jre\bin\java -p javafx-sdk-14.0.2.1\lib --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 &#39;yyyy-MM-dd&#39; from file name pattern &#39;logs/terranrepublicviewer.log.%d{yyyy-MM-dd}.log.gz&#39;.
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 &#39;yyyy-MM-dd&#39; from file name pattern &#39;logs/terranrepublicviewer.log.%d{yyyy-MM-dd}.%i.log.gz&#39;.
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 &quot;main&quot; 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 Mac\tripsnew\wintripsruntime&gt;

答案1

得分: 0

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
System.setProperty("javafx.preloader", "com.teamgannon.trips.javafxsupport.TripsPreloader");
Application.launch(TripsFxApplication.class, args);

<!-- end snippet -->
Application会查找保存预加载器的属性并正确插入。这应该有更好的文档说明,但就是这样。
英文:

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

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

System.setProperty("javafx.preloader", "com.teamgannon.trips.javafxsupport.TripsPreloader");
Application.launch(TripsFxApplication.class, args);

<!-- end snippet -->
Application will look for the property holding the preloader and insert it correctly. This should be documented better but there you go.

huangapple
  • 本文由 发表于 2020年10月5日 22:06:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64210264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定