Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Creating a project

A Quarkus project is not created by hand: the official tool generates it. The generator writes a pom.xml with the right dependencies and creates the first endpoint, a test, Docker files and the Maven wrapper. There are three equivalent ways: the code.quarkus.io website, the Quarkus CLI and the Maven plugin. We use the Maven plugin — it only needs Maven installed.

Generating the project

Open a terminal in the folder for your projects and run one command:

mvn io.quarkus.platform:quarkus-maven-plugin:3.40.1:create \
    -DprojectGroupId=com.example \
    -DprojectArtifactId=blog \
    -DpackageName=com.example.blog \
    -Dextensions="rest-jackson"

The plugin's create goal creates the blog folder. The parameters set the group and the project name, the Java package for the code and the list of extensions: rest-jackson means REST endpoints with JSON through the Jackson library. At the end the terminal prints:

[SUCCESS]  quarkus project has been successfully generated in:
--> C:\projects\blog

On Windows, type the whole command on one line instead of using \ at the line ends.

Project structure

blog/
├── pom.xml
├── mvnw, mvnw.cmd
├── .mvn/
└── src/
    ├── main/
    │   ├── docker/                     Dockerfiles for different build types
    │   ├── java/com/example/blog/
    │   │   └── GreetingResource.java   the first endpoint
    │   └── resources/
    │       └── application.properties  settings
    └── test/java/com/example/blog/
        ├── GreetingResourceTest.java   a test of the endpoint
        └── GreetingResourceIT.java     the same test for the built application
PathPurpose
pom.xmlDependencies and build plugins
mvnw, mvnw.cmdThe Maven wrapper for Linux/macOS and Windows
src/main/javaApplication code
src/main/resourcesSettings and static files
src/test/javaTests

What is in pom.xml

The key parts of pom.xml are the Quarkus platform version and the extensions:

<properties>
    <maven.compiler.release>25</maven.compiler.release>
    <quarkus.platform.version>3.40.1</quarkus.platform.version>
</properties>
 
<dependencies>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-rest-jackson</artifactId>
    </dependency>
    <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-arc</artifactId>
    </dependency>
</dependencies>

Quarkus dependencies have no versions: they come from the platform BOM file quarkus-bom, imported in pom.xml. quarkus-arc is the Quarkus CDI container, needed almost always. The generator set release 25 because it ran on Java 25.

The first endpoint

The generator has already created a class:

// src/main/java/com/example/blog/GreetingResource.java
package com.example.blog;
 
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
 
@Path("/hello")
public class GreetingResource {
 
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello from Quarkus REST";
    }
}

The class answers a GET /hello request with a line of text. The next lesson shows how to run it.

Adding extensions

Extensions can also be added after the project is created:

./mvnw quarkus:add-extension -Dextensions="hibernate-validator"

The command adds the dependency to pom.xml and prints Extension io.quarkus:quarkus-hibernate-validator has been installed. ./mvnw quarkus:list-extensions shows all available extensions.

Common mistake

Without -DpackageName the generator puts the code into a package equal to the groupId — com.example. The project works, but the blog classes end up outside com.example.blog, and the paths in the lessons no longer match. Set the package when generating, or later move the class into the right folder together with its package line.

Thanks for reading!

Donate to the site — we work hard for you.