You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was working on switching a few of our applications to GraalVM native image and I spent significant time debugging why we're unable to load our classpath resources even though I followed the documentation (https://www.graalvm.org/22.1/reference-manual/native-image/Resources/).
All the logs from the compilation (with -H:Log=registerResource:3 flag) seemed to be correct yet the app was unable to load the resource.
The culprit was using ClassLoader.getResource("classpath").getFile() and then trying to read the file instead of calling ClassLoader.getResourceAsStream(). Yeah, it makes sense, the resource is inside a native executable, it's not a regular file... But it's not obvious without prior experience :)
Describe the solution you'd like.
Let's improve the documentation Adding resources to native image to mention that the resources are not regular files and should not be approached as such.
Feature request
I was working on switching a few of our applications to GraalVM native image and I spent significant time debugging why we're unable to load our classpath resources even though I followed the documentation (https://www.graalvm.org/22.1/reference-manual/native-image/Resources/).
All the logs from the compilation (with
-H:Log=registerResource:3
flag) seemed to be correct yet the app was unable to load the resource.The culprit was using
ClassLoader.getResource("classpath").getFile()
and then trying to read the file instead of callingClassLoader.getResourceAsStream()
. Yeah, it makes sense, the resource is inside a native executable, it's not a regular file... But it's not obvious without prior experience :)Describe the solution you'd like.
Let's improve the documentation Adding resources to native image to mention that the resources are not regular files and should not be approached as such.
The same issue seems to have happened to other people (like #3092 (comment) or quarkusio/quarkus#2746 (comment) ) and although a solution was found, there was no clear explanation.
The text was updated successfully, but these errors were encountered: