Sample Project Using Quarkus Framework

Certainly! Here’s a step-by-step example of creating a simple Quarkus application:


Step 1: Set up your development environment


  • Install Java JDK 11 or later.
  • Install Apache Maven.
  • Install your favorite IDE (e.g., Eclipse, IntelliJ IDEA) with Java and Maven support.


Step 2: Create a new Quarkus project


  • Open a terminal or command prompt.
  • Run the following command to create a new Quarkus project using Maven archetype:

mvn io.quarkus:quarkus-maven-plugin:2.3.0.Final:create -DprojectGroupId=com.example -DprojectArtifactId=my-quarkus-app -DclassName="com.example.MyResource" -Dpath="/hello"

  • This command creates a new Quarkus project with a REST resource named “MyResource” mapped to the path “/hello”.


Step 3: Open the project in your IDE


  • Navigate to the project folder:

cd my-quarkus-app

  • Open the project in your IDE.


Step 4: Implement the REST resource


  • Open the file “src/main/java/com/example/MyResource.java”.
  • Replace the contents with the following code:

package com.example;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

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

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello, Quarkus!";
    }
}


Step 5: Build and run the application


  • Open a terminal or command prompt.
  • Run the following command to build and run the Quarkus application:

mvn compile quarkus:dev

  • This command starts the Quarkus development mode, which automatically rebuilds and restarts the application whenever you make changes to the code.


Step 6: Test the application


  • Open a web browser or use an API testing tool (e.g., cURL, Postman).
  • Access the following URL: http://localhost:8080/hello
  • You should see the response “Hello, Quarkus!”.

Congratulations! You have created a simple Quarkus application. You can continue building on this foundation by adding more resources, services, and dependencies as needed.


Leave a Reply

Your email address will not be published. Required fields are marked *