Quarkus Hello World application

 Quarkus Hello World application

Purpose: In this post, we will learn how we can create a Hello World Quarkus application. The steps are given below.

1. Setup and Create Project: There is two way to create a new project.

a-: We can create a new project online following the link https://code.quarkus.io/

b-: Creating Using STS

Step: Download STS https://spring.io/tools

Next Step. Open STS and go to the marketplace and search Quarkus plugin.


Next Step. In STS go to File->New->Others then select Quarkus

Next Step. Select project type and define project name, package name etc..



Next Step. Add dependencies as you required.


Project Structure: Your project structure looks like as shown in the below image.


Next Step. Quarkus Parent Dependencies.


    <properties>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
        <quarkus.platform.version>2.2.3.Final</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
Next Step. Project Dependencies.


       <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</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>
    </dependencies>
Next Step. Quarkus HelloWorld Resource


package org.bce;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello")
public class HelloWorld {

    @GET
    public String hello() {
        return "Hello Quarkus";
    }
}
Next Step. Server Port:  The default server port is 8080. Wish you want to change open application.properties and add the below line.

quarkus.http.port=8081

Next Step. Run the application. See demo below.



Download Code from GitHub.  Source Code




No comments:

Post a Comment