Open horvathandras opened 5 years ago
You can find more information about class initialization in this blog article.
I found the linked article while I was trying to understand what I was doing wrong, but it did not enlighten me. As far as I understand in the very moment when I try to create a JFrame, I indirectly import a class which opens a file in a static context (reading a TTF file for the menu of the window I guess) and interacts with a thread (the EDT I guess) which actions are not allowed on the image heap as the result of them will not be present in the runtime environment. So should I delay the initialization of the said class to be done at runtime with the --delay-class-initialization-to-runtime option? If yes, then which class should be delayed?
With GraalVM 19 the default behavior of class initialization has now flipped. But I still can't create any Native Image of a Swing application. I tested the code above with 19.2.1. But with no luck. It would be really cool to have a native image for my small swing app. The memory footprint of many hip desktop apps are crazy. I don't want to waist more gigabytes with my one.
I'm trying to create a native image of a basic swing application.
Building it with
The result is
I tried to understand how the class initialization works in the native image generation and that native resources and threads should not be allocated in static fields/initializers. But I'm still a bit puzzled here what am I doing wrong. As I'm trying to understand the first segment of the error message, I see that a TTF file is probably loaded in a static class initialization context while the window is created. But how can I avoid that?