edvin / tornadofx

Lightweight JavaFX Framework for Kotlin
Apache License 2.0
3.68k stars 272 forks source link

CSS URL Protocol - GraalVM Native Image Compatibility? #1334

Open dkim19375 opened 3 years ago

dkim19375 commented 3 years ago

When using native image with TornadoFX, I get this warning:

The URL protocol css is not tested and might not work as expected.
Supported URL protocols enabled by default: file,resource. Supported URL protocols available on demand: http,https.
Registering the css URL protocol failed. It will not be available at runtime.

and when running the exe, it throws an exception -

Jun 26, 2021 4:56:42 PM tornadofx.Stylesheet$Companion detectAndInstallUrlHandler
INFO: Installing CSS url handler, since it was not picked up automatically
Jun 26, 2021 4:56:42 PM tornadofx.Stylesheet$Companion detectAndInstallUrlHandler
WARNING: Unable to install CSS url handler, type safe stylesheets might not work
java.net.MalformedURLException: Accessing an URL protocol that was not enabled. The URL protocol css is not tested and might not work as expected. It can be enabled by adding the --enable-url-protocols=css option to the native-image command.
        at com.oracle.svm.core.jdk.JavaNetSubstitutions.unsupported(JavaNetSubstitutions.java:222)
        at com.oracle.svm.core.jdk.JavaNetSubstitutions.getURLStreamHandler(JavaNetSubstitutions.java:177)
        at java.net.URL.getURLStreamHandler(URL.java:72)
        at java.net.URL.<init>(URL.java:651)
        at java.net.URL.<init>(URL.java:541)
        at java.net.URL.<init>(URL.java:488)
        at tornadofx.Stylesheet$Companion.detectAndInstallUrlHandler(CSS.kt:469)
        at tornadofx.Stylesheet$Companion.access$detectAndInstallUrlHandler(CSS.kt:97)
        at tornadofx.Stylesheet.<clinit>(CSS.kt:448)
        at com.oracle.svm.core.classinitialization.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:375)
        at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:295)
        at tornadofx.App.<init>(App.kt:73)
        at me.dkim19375.project.Project.<init>(Project.kt:25)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
        at java.security.AccessController.doPrivileged(AccessController.java:100)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST:Ljava_lang_Runnable_2_0002erun_00028_00029V(JNIJavaCallWrappers.java:0)
        at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java)
        at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
        at java.lang.Thread.run(Thread.java:829)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:553)
        at com.oracle.svm.core.windows.WindowsJavaThreads.osThreadStartRoutine(WindowsJavaThreads.java:138)

Exception in Application start method

Anyone know how I'd fix this? My overall goal is to avoid installations, including java and this program itself (which GraalVM Native Image does), so if anyone can find an alternative or know a solution, please let me know! :)

Anivie commented 2 years ago

Have you found a solution? I also found this problem but couldn't solve it

dkim19375 commented 2 years ago

Have you found a solution? I also found this problem but couldn't solve it

Nope :/

I think that you'd have to either:

chengenzhao commented 2 years ago

Does Jetbrains Compose could make native image right now?

dkim19375 commented 2 years ago

Does Jetbrains Compose could make native image right now?

I don't know, but it doesn't use CSS, which is why I put it on the reply. (and the error seems to be about using the CSS url protocol)

CXwudi commented 2 years ago

Would love to see TornadoFX or JetBrains Compose who first supports GraalVM native image.

dkim19375 commented 2 years ago

Would love to see TornadoFX or JetBrains Compose who first supports GraalVM native image.

What happens when you use Compose?

CXwudi commented 2 years ago

Would love to see TornadoFX or JetBrains Compose who first supports GraalVM native image.

What happens when you use Compose?

Tbh I haven't tried to migrate Compose to native image yet, but neither did I find any documents or blog posts about how to do it

dkim19375 commented 2 years ago

Would love to see TornadoFX or JetBrains Compose who first supports GraalVM native image.

What happens when you use Compose?

Tbh I haven't tried to migrate Compose to native image yet, but neither did I find any documents or blog posts about how to do it

Native image doesn't need specific docs for each library (unless there's compatibility issues like TornadoFX), as it just "converts" the JAR to an EXE

CXwudi commented 2 years ago

@dkim19375 I just tried on Compose using a HelloWorld example with Graalvm 17 CE, Native Image can only produce a fallback image, which still requires a JDK to run

dkim19375 commented 2 years ago

@dkim19375 I just tried on Compose using a HelloWorld example with Graalvm 17 CE, Native Image can only produce a fallback image, which still requires a JDK to run

O

wait have I been misunderstanding native image all this time-

CXwudi commented 2 years ago

@dkim19375 The reason why generating a (non-fallback) native image is hard is because the native image doesn't allow any Java reflection. https://www.graalvm.org/22.0/reference-manual/native-image/Limitations/

This requires a closed-world assumption, where all code is known at image build time, i.e., no new code is loaded at run time. As with most optimizations, not all applications are amenable for that optimization. If an application is not optimizable, then a so-called fallback image is generated that launches the Java HotSpot VM, i.e., requires a JDK for execution.

dkim19375 commented 2 years ago

@dkim19375 The reason why generating a (non-fallback) native image is hard is because the native image doesn't allow any Java reflection. https://www.graalvm.org/22.0/reference-manual/native-image/Limitations/

oh hmmmm then I'm assuming Compose wouldn't work either

oh is that what you meant by

Native Image can only produce a fallback image, which still requires a JDK to run

?

CXwudi commented 2 years ago

@dkim19375 Pretty much, that's why I am waiting to see Compose and TurnadoFX who will support the (non-fallback) native image first.

Btw, pure JavaFX (by Gluon JavaFX) is already supported to be built as a GraalVM native image, but that is with pure Java code and without DI. It might be possible to integrate Kotlin into it, but I haven't tried it yet nor will I try it as I would prefer TornadoFX or Compose