native-build-tools
native-build-tools copied to clipboard
Cannot read resources from the native image
Hi ! I am trying to load resources run time. This seems to fail when doing it with native-image.
I found this on my project when T.class.getClassLoader().getResource(fileName)
.
I am using Java 17 , GraalVM graalvm-ce-java17-22.3.1, native-maven-plugin:0.9.19
But also I tried your example repo
and it is not working also which is using getResourceAsStream(fileName)
To Reproduce
Use
repo
Execute:
mvn -Pnative clean package
(Also tried mvn -Pnative clean native:compile
)
And it is failing
[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.9.19:test (test-native) on project maven-app-with-tests: Execution of /home/joroivanov/FT/graalvm_samples/native-build-tools/samples/java-application-with-resources/target/native-tests --xml-output-dir /home/joroivanov/FT/graalvm_samples/native-build-tools/samples/java-application-with-resources/target/native-test-reports -Djunit.platform.listeners.uid.tracking.output.dir=/home/joroivanov/FT/graalvm_samples/native-build-tools/samples/java-application-with-resources/target/test-ids returned non-zero result ->
Even if I skip the tests , the image is build but when I start the image it is throwing an exception.
Exception in thread "main" java.lang.NullPointerException
at [email protected]/java.io.Reader.<init>(Reader.java:168)
at [email protected]/java.io.InputStreamReader.<init>(InputStreamReader.java:76)
at org.graalvm.demo.Application.getMessages(Application.java:11)
at org.graalvm.demo.Application.main(Application.java:16)
Expected behavior
Hello, native!
logged in the console.
System Info (please complete the following information):
- OS: [
Debian 11
] - GraalVM Version [
22.3.1
] - Java Version [
17
] - Plugin version [
native-maven-plugin:0.9.19
]
Additional context Note: I have to change plugin version to 0.9.19 as 0.9.20-SNAPSHOT is not in maven repo.