Skip to content

Creating a new Quarkus app

Development environment

Prerequisites

  1. JDK >= 17
Terminal window
java -version
  1. Apache Maven
Terminal window
mvn -version
  1. IDE

An IDE like IntelliJ IDEA or Visual Studio Code with Java extensions.

  1. GraalVM (optional but recommended)

For native compilation: GraalVM

  1. Quarkus CLI (optional)

Using SDKMAN:

Terminal window
curl -s "https://get.sdkman.io" | bash
Terminal window
sdk install quarkus
Terminal window
quarkus --version

Create a New Quarkus Project

  • Using the CLI:
Terminal window
quarkus create app com.capco:quarkus-quickstart:1.0-SNAPSHOT
  • Using Maven:
Terminal window
mvn io.quarkus.platform:quarkus-maven-plugin:3.0.0.Final:create \
-DprojectGroupId=com.capco \
-DprojectArtifactId=quarkus-quickstart \
-DprojectVersion=1.0-SNAPSHOT \
-DclassName="com.capco.GreetingResource" \
-Dpath="/hello"

Explore the file structure

  • pom.xml
  • Directorysrc
    • main
    • resources
    • test

Run the application in development mode

Terminal window
./mvnw quarkus:dev

Add features to the Quarkus application

  • Add a new service class:
@ApplicationScoped
public class GreetingService {
public String greeting(String name) {
return "Hello, " + name;
}
}
  • Update the resource class to use the service:
@Inject
GreetingService greetingService;
@GET
@Path("/greet/{name}")
@Produces(MediaType.TEXT_PLAIN)
public String greet(@PathParam("name") String name) {
return greetingService.greeting(name);
}

Test the application

@QuarkusTest
public class GreetingResourceTest {
@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is("Hello, World!"));
}
}