I have .png files in src/main/resources that I want to access on my deployed Quarkus app, but when I use Thread.currentThread().getContextClassLoader().getResource("image.png") it points me to the jar file.
io.vertx.core.file.FileSystemException: Unable to open file at path '/file:/deployments/app/app-api-1.0.0-SNAPSHOT.jar!/image.png'
However, when I use Thread.currentThread().getContextClassLoader().getResource("image.png") while running the app in my IDE, the ContextClassLoader points to the target/classes folder.
I have tried including them in META-INF/resources.
I have tried quarkus.native.resources.includes=*.png
Is there a solution that will work for both locally in my IDE as well as deployed on a container/in a native image?
2
Answers
For anyone facing a similar problem in the future, what ended up working for me was using the .getResourceAsStream() method instead of .getResource(). I am not knowledgeable about how these things operate, but it looks like .getResourceAsStream() makes a 'connection' to the JAR while .getResource() doesn't.
META-INF/resources
is the directory Quarkus uses for it’s web server, but the java standard is everything inresources
get’s packaged in the jar’s class path.so if your file is here:
src/main/resources/META-INF/resources
The proper way to reference it is:
When loading the file with getResource, you can put the file anywhere in your resources directory, like:
src/main/resources/image.png
.It will then be available with: