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.43k stars 1.64k forks source link

[Native Image] ClassNotFoundException #9930

Open Ferrarisrex opened 1 month ago

Ferrarisrex commented 1 month ago

Describe the Issue

I package and compile the jar using the maven native image plugin, and the output works fine on the computer that compiled it, even if i change the executables directory, however, if i put it on a different computer, I get java.lang.ClassNotFoundException: com.sun.prism.shader.Mask_TextureSuper_Loader i did bring all the DLL files with it, and the target computer has java 1.8

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

java version "21.0.4" 2024-07-16 LTS Java(TM) SE Runtime Environment Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.4+8.1 (build 21.0.4+8-LTS-jvmci-23.1-b41, mixed mode, sharing)

Operating System and Version

Windows 10 22h2

Diagnostic Flag Confirmation

Run Command

image.exe

Expected Behavior

to finish running

Actual Behavior

opens a menu, and then has the above error constantly reoutputted to the command prompt and does not continue

Steps to Reproduce

  1. Run the file

Additional Context

No response

Run-Time Log Output and Error Messages

No response

Karm commented 1 month ago

@Ferrarisrex Help us help you with a small reproducer, an application you can share that demonstrates this behavior. You most definitely need libraries from the GraalVM distro, not anything pulled from Java 1.8.

Ferrarisrex commented 1 month ago

I can not reproduce the error without the code I already made, so I do not know the app works fine on computers that compile it, but if I open up a VM of the same OS on that pc, I get that error. is there any way to make sure that the class is included in reflection? it doesn't seem to work with the automatic reflection generator

Ferrarisrex commented 1 month ago

I tried fixing it by just copying the format of the other shaders in reflect-config.json, but that results in a InvocationTargetExcaption

Ferrarisrex commented 1 month ago

I tried it differently, doing: name: com.sun.prism.shader.Mask_TextureSuper_Loader allDeclaredClasses: true allPublicClasses: true but it says method not found com.sun.prism.shader.Mask_TextureSuper_Loader.loadShader()

Ferrarisrex commented 1 month ago

if I do -H:IncludeResources=".*" it works, but the file size is huge, but if i do -H:IncludeResources="com.sun.prism.shader.Mask_TextureSuper_Loader.class" it does not work

oubidar-Abderrahim commented 1 month ago

Did you try building your native-image from a jar-with-dependencies?

Ferrarisrex commented 1 month ago

i did do that

Ferrarisrex commented 1 month ago

i did find a workaround, you must do the following: in your reflect-config.json you must add: { "name":"com.sun.prism.shader.Mask_TextureSuper_Loader", "allDeclaredClasses":true, "allPublicClasses":true, "methods":[{"name":"loadShader","parameterTypes":["com.sun.prism.ps.ShaderFactory","java.io.InputStream"] }] },

and in your pom.xml you must add: \-H:IncludeResources=".*/prism/.*"\ \-H:IncludeResources=".*/sun/scenario/effect/.*"\

this does seem to work for other missing classes of the same flavor, such as com.sun.prism.shader.Solid_Color_Loader, just change the name in reflect-config.json i put this together without really knowing what i was doing or how things work, so there is probably a better way to do this, please do tell if you know, but this does work well