oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.45k stars 1.64k forks source link

java.lang.ClassNotFoundException: com.sun.javafx.tk.quantum.QuantumToolkit #7521

Open damnms opened 1 year ago

damnms commented 1 year ago

i have an application (https://gitlab.com/olze/chatclient) that i'd like to move to a native image. the build works but when i execute it, i get an error:

oli@DESKTOP-SJIB21T:~/IdeaProjects/chatclient/build/native/nativeCompile$ ./chatclient 
Sept. 30, 2023 8:12:15 AM com.sun.javafx.application.PlatformImpl startup
WARNUNG: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @10bdf5e5'
java.lang.ClassNotFoundException: com.sun.javafx.tk.quantum.QuantumToolkit
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:122)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:86)
    at java.base@21/java.lang.Class.forName(DynamicHub.java:1346)
    at java.base@21/java.lang.Class.forName(DynamicHub.java:1335)
    at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:253)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:290)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:162)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:651)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:671)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base@21/java.lang.Thread.runWith(Thread.java:1596)
    at java.base@21/java.lang.Thread.run(Thread.java:1583)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)
Exception in thread "main" java.lang.RuntimeException: No toolkit found
    at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:275)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:290)
    at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:162)
    at com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:651)
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:671)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base@21/java.lang.Thread.runWith(Thread.java:1596)
    at java.base@21/java.lang.Thread.run(Thread.java:1583)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:833)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211)
damnms commented 1 year ago

I use gradle and gradle javafx plugin, so i am not 100% sure if this is a problem in https://github.com/openjfx/javafx-gradle-plugin or in graalvm/javafx

chirontt commented 1 year ago

When compiling JavaFX application to native image, the org.graalvm.buildtools.native tool doesn't handle the JavaFX modules properly, resulting in those java.lang.ClassNotFoundException thrown at runtime. You should use a more specialized tool for producing JavaFX native image: gluonfx

But then, I still get some different runtime exceptions with your app's native image when using the gluonfx tool. My guess is that the gluonfx tool somehow doesn't handle the javafx.web module correctly (missing its OS-native library in the resulting image, for some reason). Perhaps you should replace the use of javafx.web module in your app (e.g. replacing the usage of WebView class), to see if it helps?

kamel2005 commented 11 months ago

I have the same issue with graalvm v 17.x, but i it worked in previous version that i have been deleted. I think 19.x with OpenJDK 11.x. I hope somebody would fix it or find somehow solution

damnms commented 11 months ago

i am not affected by this anymore because i left graalvm (because of such problems) and went the jpackage approach, but i leave this ticket open for others that are affected.

fernando-valdez commented 10 months ago

Hello @kamel2005 and @kamel2005, can you please share the exact steps we need to take to get that error, including a reproducer? And just to be sure, @kamel2005 mentioned that this was not a problem on previous versions of GraalVM, can you please share the version that can work with your project?

kamel2005 commented 10 months ago

1) Run the application with the tracing agent enabled: java -cp "lib" -p "lib" --add-modules ALL-MODULE-PATH -agentlib:native-image-agent=config-output-dir=META-INF/native-image -jar yourapp.jar.jar

2) Generate Native Image
native-image --no-fallback --link-at-build-time --enable-all-security-services -H:ReflectionConfigurationFiles="META-INF\native-image\reflect-config.json -H:+TraceSecurityServices -H:+ReportExceptionStackTraces --verbose -H:Log=registerResource:3 -H:Name=SecureNote-1.0 -H:Class=com.yourpackagename.MainApp -cp lib1.jar; lib2.jar ... ; yourapp.jar

Note: replace with your jar, lib and package names

As I mentioned in my previous post, I don't remember the exact versions that worked before neither i have any of these versions.