Creating a new Quarkus app
Development environment
Prerequisites
- JDK >= 17
java -version
- Apache Maven
mvn -version
- IDE
An IDE like IntelliJ IDEA or Visual Studio Code with Java extensions.
- GraalVM (optional but recommended)
For native compilation: GraalVM
- Quarkus CLI (optional)
Using SDKMAN:
curl -s "https://get.sdkman.io" | bash
sdk install quarkus
quarkus --version
Create a New Quarkus Project
- Using the CLI:
quarkus create app com.capco:quarkus-quickstart:1.0-SNAPSHOT
- Using Maven:
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
./mvnw quarkus:dev
Add features to the Quarkus application
- Add a new service class:
@ApplicationScopedpublic class GreetingService { public String greeting(String name) { return "Hello, " + name; }}
- Update the resource class to use the service:
@InjectGreetingService greetingService;
@GET@Path("/greet/{name}")@Produces(MediaType.TEXT_PLAIN)public String greet(@PathParam("name") String name) { return greetingService.greeting(name);}
Test the application
@QuarkusTestpublic class GreetingResourceTest {
@Test public void testHelloEndpoint() { given() .when().get("/hello") .then() .statusCode(200) .body(is("Hello, World!")); }}