Let's get started with a Microservice Architecture with Spring Cloud:
Access Resources in a Quarkus Native Image
Last updated: December 8, 2025
1. Introduction
Quarkus is a Java framework that promises to deliver small artifacts, extremely fast boot time, and lower time-to-first-request. We achieve this by creating native images using GraalVM. When developing Quarkus applications, we may need access to resources such as text files that are bundled with the image or made available externally.
In this tutorial, we’ll examine different ways of making resources available to an application that is bundled as a Quarkus Native Image.
2. Project Configuration
We’ll create an example project to help us understand the different ways of loading resource files inside a Quarkus Native Image.
2.1. Creating a Project
We require a JDK and Quarkus CLI installed as prerequisites. Once the prerequisites are available, we can create a new project:
$ quarkus create app quarkus-resources
This should create a new project under the folder named quarkus-resources with basic scaffolding for a Quarkus project.
2.2. Dependencies
The project created using the quarkus CLI automatically adds core dependencies (quarkus-arc and quarkus-junit5) and dependencies for REST services (quarkus-rest, rest-assured). In addition, we need quarkus-rest-jackson for working with JSON in the input or output of the REST services:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
3. Accessing Resources
Now that we have a project scaffolding ready, we’re ready to start accessing the resources through the code.
It’s important to note that GraalVM does not include any of the resources that are on the classpath into the native executable it creates. Resources that are meant to be part of the native executable need to be configured explicitly.
Quarkus provides us with a few different ways of accessing resources inside the application.
3.1. Public Resources
As with any Web application, we typically may need to expose some static web content such as HTML, JavaScript, and CSS. Quarkus automatically exposes the contents of META-INF/resources as web content.
We note that the META-INF/resources directory is meant for public resources only. We shouldn’t use this directory to put any non-public resources. This directory can be used to place all sorts of web content, but for our test, we placed a simple index.html inside this directory with the contents:
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello from Baeldung!</h1>
</body>
</html>
Then, we add a test to check the contents:
@Test
@DisplayName("should return content from index.html")
void givenIndexPage_whenGetRootUrl_thenReturnsContent() {
given()
.when().get("/")
.then()
.statusCode(200)
.body(containsString("Hello"));
}
3.2. Property Configuration
We’ll create a couple of text files named default-resource.txt and text/another-resource.txt and place them under the resource directory src/main/resources. Unlike jar packaging, the contents of src/main/resources are not automatically present in the native image.
Therefore, we note that these resources need to be configured explicitly to be available in the code. This configuration can be added in application.properties as a comma-separated list of glob patterns:
quarkus.native.resources.includes=text/**,*.txt
Then, we’ll create a method to allow us access to a given resource:
private String readResource(String resourcePath) throws IOException {
LOGGER.info("Reading resource from path: {}", resourcePath);
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath)) {
if (in == null) {
LOGGER.error("Resource not found at path: {}", resourcePath);
throw new IOException("Resource not found: " + resourcePath);
}
LOGGER.info("Successfully read resource: {}", resourcePath);
return new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining("\n"));
}
}
Finally, we’ll add a method to expose the contents of these resources through an API endpoint:
@GET
@Path("/default”)
@Produces(MediaType.TEXT_PLAIN)
public Response getDefaultResource() throws IOException {
return Response.ok(readResource("default-resource.txt")).build();
}
With that, we have successfully read the default-resource.txt from the classpath and exposed its contents through an API. In real projects, we’d perhaps use the contents differently. Next, we’ll use Junit for the test:
@Test
@DisplayName("should return content from default resource")
void whenGetDefaultResource_thenReturnsContent() {
given()
.when().get("/resources/default")
.then()
.statusCode(200)
.body(is("This is the default resource."));
}
3.3. Resource Configuration File
While the application.properties configuration offers a quick way to provide access to resources, sometimes the configuration can be more complex. In such a case, we may want to offer many different patterns to cover the files of interest.
GraalVM allows such configuration through the use of the resource-config.json:
{
"resources": [
{
"pattern": ".*\\.json$"
}
]
}
We need to place this file under the folder src/main/resources/META-INF/native-image/<group-id>/<artifact-id>, and then the Quarkus build will take care of making the files available for use inside the code. Next, we create a separate endpoint to expose the contents of this file:
@GET
@Path("/json")
@Produces(MediaType.APPLICATION_JSON)
public Response getJsonResource() throws IOException {
return Response.ok(readResource("resources.json")).build();
}
Now we can test this:
@Test
@DisplayName("should return content from included json resource")
void whenGetJsonResource_thenReturnsContent() {
given()
.when().get("/resources/json")
.then()
.statusCode(200)
.body("version", is("1.0.0"));
}
So now we’ve successfully exposed resources using a resource-config file and patterns.
4. Manual Test of the APIs
We now have a few APIs that expose a few different resources, and we’ve written unit tests to check the expected output from the other API calls. We note, however, that Junit tests do not test the native image, and a true test of the availability of resources is to test the relevant API URLs from the native build.
Therefore, to properly test this, we can run a native build of the project:
$ mvn clean install -Pnative
This will create a native executable of the form <project-name>-<version>-runner under the target problem. We can run this executable and then test it using a browser or the curl command:
$ curl -X GET http://localhost:8080/resources/default
We expect this URL to return the contents of the default-resource.txt file. Similarly, we can also manually test the other URLs.
5. Conclusion
In this article, we configured an API using Quarkus and accessed file resources on the server using a Quarkus native image. We reviewed the different ways to access classpath resources from code. We need explicit configuration to access the resources on the classpath.
As always, the code is available over on GitHub.
















