我正试图为一个与Quarkus和JavaFx一起工作的应用程序构建一个本地可执行文件。我实现这一目标的唯一方法是将许多javaFx类标记为--在运行时初始化,但这会导致在尝试启动应用程序时,它会失败,并发出以下消息:
java.lang.ClassNotFoundException: com.sun.javafx.tk.quantum.QuantumToolkit
at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:71)
at java.lang.Class.forName(DynamicHub.java:1319)
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:251)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.lang.Thread.run(Thread.java:829)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:567)
at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:138)
2021-09-09 16:02:21,173 ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): java.lang.RuntimeException: No toolkit found
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:273)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.lang.Thread.run(Thread.java:829)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:567)
at
com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:138)
我想我需要在构建之前添加javafx模块,但不知道如何从Maven中实现这一点。如果有人能帮我,我会非常感激的。提前谢谢。
PS:如果有人知道使用springboot的替代解决方案,请分享:)
更新:用SpringBoot测试,而spring本地版和gluonfx也失败了.
使您可以从:https://github.com/ikaro143/JavaFx-SpringBoot-example/tree/master下载一个最小的可复制性
maven命令应该在VisualStudio本机工具命令Promp中执行
使用spring插件构建:mvn clean package -Pnative
使用gluonfx构建:mvn clean gluonfx:build -Pnative-gluonfx
在这两种情况下,.exe都是构建的,但两者都不起作用。
从控制台执行spring编译会引发这个stackTrace (胶子构建的执行不会给出任何反馈,但都不起作用):
Exception in thread "main" java.lang.RuntimeException: Application launch error
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:202)
at java.lang.Thread.run(Thread.java:829)
at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:567)
at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:138)
Caused by: java.lang.AssertionError: java.lang.ClassNotFoundException: javafx.scene.image.Image
at com.sun.javafx.util.Utils.forceInit(Utils.java:868)
at com.sun.javafx.tk.Toolkit.<clinit>(Toolkit.java:945)
at com.oracle.svm.core.classinitialization.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:375)
at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:295)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:286)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:160)
at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:678)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
... 3 more
Caused by: java.lang.ClassNotFoundException: javafx.scene.image.Image
at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:71)
at java.lang.Class.forName(DynamicHub.java:1319)
at com.sun.javafx.util.Utils.forceInit(Utils.java:865)
... 11 more
更新:共享Quarkus + Jafavx的最小可重现性
https://github.com/ikaro143/JavaFx-Quarkus-example
使用夸克插件构建:mvn clean package -Pnative
使用gluonfx构建:mvn clean gluonfx:build -Pnative-gluonfx
Quarkus方法在分析步骤上失败了。有以下几个错误:
analysis: 45,621.43 ms, 3.89 GB
Error: Unsupported features in 12 methods
Detailed message:
Error: Class initialization of com.sun.javafx.tk.quantum.PrismImageLoader2$AsyncImageLoader failed. Use the option --initialize-at-run-time=com.sun.javafx.tk.quantum.PrismImageLoader2$AsyncImageLoader to explicitly request delayed initialization of this class.
Original exception that caused the problem: java.lang.ExceptionInInitializerError
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)
at jdk.unsupported/sun.misc.Unsafe.ensureClassInitialized(Unsafe.java:698)
at jdk.internal.vm.compiler/org.graalvm.compiler.serviceprovider.GraalUnsafeAccess.ensureClassInitialized(GraalUnsafeAccess.java:77)
在安装步骤中,gluonfx方法失败,出现了以下模糊错误:
[com.quarkusjavafx.example.applauncher.cdiapplication:9740] classlist: 3,592.40 ms, 1.19 GB
[com.quarkusjavafx.example.applauncher.cdiapplication:9740] (cap): 3,086.44 ms, 1.19 GB
[com.quarkusjavafx.example.applauncher.cdiapplication:9740] setup: 6,095.10 ms, 1.19 GB
Fatal error:java.lang.NullPointerException
at java.base/java.io.Reader.<init>(Reader.java:167)
at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at io.quarkus.runtime.graal.ResourcesFeature.beforeAnalysis(ResourcesFeature.java:21)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$11(NativeImageGenerator.java:691)
at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:71)
at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:691)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:532)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:491)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:380)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:543)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:119)
at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:573)
[com.quarkusjavafx.example.applauncher.cdiapplication:9740] [total]: 9,723.35 ms, 1.19 GB
发布于 2021-09-13 12:12:16
更新了,根据José Pereda的建议,我尝试将后端迁移到Micronaut,并且能够成功地构建本地映像。从弹簧到米洛诺的迁移是很容易做到的。只需更改pom中的父级和基本依赖项。
本机映像由maven代码生成:mvn clean gluonfx: build -Pnative-gluonfx
也许您需要首先使用目标gluonfx:runagent
来生成运行所需的配置文件。
在我的经验中,我遇到了一些依赖问题,只有在构建完成后运行目标gluonfx:nativerun
时才注意到这些问题。然后调整代码。
我在这里留下一个极小的例子,以防有人需要它:https://github.com/ikaro143/example-micronaut
PS:确保您的主类已注册以进行反射。
https://stackoverflow.com/questions/69119724
复制相似问题