-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraalVM: ClassNotFoundException: com.googlecode.lanterna.gui2.WindowShadowRenderer #584
Comments
Renderer classes are not directly accessed in Java-code, but dynamically
loaded "by name" at runtime.
If you have a build-tool that will only pick classes that are "accessed",
then these tools will not see the necessity of those extra classes, and
thus not include them.
One workaround is, to directly use those Renderer-classes that you appear
to need(based on thrown exceptions), in your own code, or maybe you
can tell the build tool to add a given list of classes *always* -
regardless of any analyzed need for those classes.
…On Wed, Oct 25, 2023 at 10:17 AM damnms ***@***.***> wrote:
Hi, i have a little application and would love to create native images
with graalvm.
Unfortunately, when i run the built native-image, i get:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.googlecode.lanterna.gui2.AbstractTextGUI.<init>(AbstractTextGUI.java:60)
at com.googlecode.lanterna.gui2.MultiWindowTextGUI.<init>(MultiWindowTextGUI.java:169)
at com.googlecode.lanterna.gui2.MultiWindowTextGUI.<init>(MultiWindowTextGUI.java:76)
at com.googlecode.lanterna.gui2.MultiWindowTextGUI.<init>(MultiWindowTextGUI.java:65)
at jsfdl.adapters.CursesWindow.<init>(CursesWindow.java:52)
at jsfdl.ApplicationConfiguration.getGui(ApplicationConfiguration.java:62)
at jsfdl.adapters.GuiApplication.main(GuiApplication.java:10)
at ***@***.***/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.googlecode.lanterna.gui2.WindowShadowRenderer
at com.googlecode.lanterna.graphics.AbstractTheme.instanceByClassName(AbstractTheme.java:154)
at com.googlecode.lanterna.graphics.PropertyTheme.<init>(PropertyTheme.java:66)
at com.googlecode.lanterna.bundle.DefaultTheme.<init>(DefaultTheme.java:11)
at com.googlecode.lanterna.bundle.LanternaThemes.<clinit>(LanternaThemes.java:52)
... 8 more
Caused by: java.lang.ClassNotFoundException: com.googlecode.lanterna.gui2.WindowShadowRenderer
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.lang.Class.forName(DynamicHub.java:1346)
at ***@***.***/java.lang.Class.forName(DynamicHub.java:1309)
at ***@***.***/java.lang.Class.forName(DynamicHub.java:1302)
at com.googlecode.lanterna.graphics.AbstractTheme.instanceByClassName(AbstractTheme.java:152)
... 11 more
line 52 of CursesWindow is: final WindowBasedTextGUI textGUI = new
MultiWindowTextGUI(screen);
So i assume its something with MultiWindowTextGUI, but thats just me
guessing :)
—
Reply to this email directly, view it on GitHub
<#584>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABIDBMSWK6WMJG2ZHRERL3TYBDDLBAVCNFSM6AAAAAA6O6IQH2VHI2DSMVQWIX3LMV43ASLTON2WKOZRHE3DAOBRHA4DMNI>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
all classes thare are instantiated by reflection are: any idea how to use the direct renderer classes? guess thats the easiest workaround/solution |
I'd really suggest adding the classes to some "white-list" of the
build tool. That would be the cleanest solution.
If you don't want to deal with the specifics of the build-tool, then
you can try the following tricks:
To a class that is already included in the build, like e.g. the main
class of your project,
you add a dummy() method like:
```
public int pullIn() {
return WindowShadowRenderer.class.toString().length() +
FatWindowDecorationRenderer.class.toString().length() +
...;
}
```
Try it - I'd think it will already pull in all these classes - don't
forget the `import` for each fully qualified classname.
If some tooling complains about the unused method dummy(), you can
call dummy() and compare it's result to
be greater-or-equal to 0, which is a pretty safe bet, so you can make
some parts of your main method dependent
on whether ` dummy() >= 0 ` .
Not very nice, sure, so that's why I'd rather suggest manually
configuring the build-tool to just unconditionally include those
classes.
…On Wed, Oct 25, 2023 at 3:04 PM damnms ***@***.***> wrote:
all classes thare are instantiated by reflection are:
com.googlecode.lanterna.gui2.WindowShadowRenderer
com.googlecode.lanterna.gui2.FatWindowDecorationRenderer
com.googlecode.lanterna.gui2.Button$DefaultButtonRenderer
any idea how to use the direct renderer classes? guess thats the easiest workaround/solution
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
my build tool is gradle, i dont know how i can "whitelist" some classes. i guess that has to be done in the graalvm native image task. i tried adding those classes that i need in my code, but that did not work:
when i run the compiled image, it says:
so i guess something is not working correctly. maybe the compiler removes that by some sort of optimization algorithm, no idea... |
to make sure its not optimized away i used real instances and got the following outpu: so the classes are there, they can be instantiated. seems like this is something else thats not working. |
seems like #521 is the same problem |
ah, that's why i had that deja-vu...
so, you still get the same classnotfound exception?
what kind of "executable" does gradle produce? is it still essentially a
zipfile, or something completely different? Does such a gradle program
thing even support dynamic loading of classes in the first place?
damnms ***@***.***> schrieb am So., 29. Okt. 2023, 09:52:
… seems like #521 <#521> is the
same problem
—
Reply to this email directly, view it on GitHub
<#584 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABIDBMQ7IISW3I4C2J5WJYLYBYDL5AVCNFSM6AAAAAA6O6IQH2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGAZTQMJQGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
gradle does not really produce an executable, its just like maven. it has some addons/plugins that can e.g. create a shadowjar (aka fatjar). and gradle can handle graalvm - which really produces a standalone application.
its a real executable and yes, graalvm supports reflection: https://www.graalvm.org/22.2/reference-manual/native-image/guides/build-with-reflection/ when i grep that binary or search with vim, i find some of those WindowShadowRenderer, so i am really lost whats going on |
i think i got it working... first i created the shadow jar, which produces the mentioned errors above (classnotfound etc.). |
Hi, i have a little application and would love to create native images with graalvm.
Unfortunately, when i run the built native-image, i get:
line 52 of CursesWindow is: final WindowBasedTextGUI textGUI = new MultiWindowTextGUI(screen);
I assume its because of the dynamic loading in AbstractTheme.java:152, wondering if i can somehow manually "add" those classes that are required (for linux/windows/mac) to graalvm, so they are packaged.
The text was updated successfully, but these errors were encountered: