Quarkus Hello World Program

How To Write HelloWorld Program in Quarkus

We can develop our 1st quarkus application using 2 ways.

1. Using Commandline.
2. Generating through https://code.quarkus.io/

Here we will use the 2nd approach ie using https://code.quarkus.io/




Fill group ,artifact and select the build tool.

Click on more options.

Select Java Version.


Check the checkbox RESTEasy Reactive.

Click on Generate your Application.

Click on Download The ZIP on the popup.

You will get the zip file. Extract it.


Open with any IDE.

I am using Intlej as the IDE here.

Navigate to the GreetingResource Class. This is the default class provided by the generator.



package org.letustryandlearn;

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 GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello from RESTEasy Reactive";
    }
}


Run the application. By default, it will run on the 8080 port.


You can see the Congratulations! page.

Click on hello. (http://localhost:8080/hello). You can see the response as "Hello from RESTEasy Reactive"

If you get the error as the port is already used then you can change the port in the application.properties by adding 
quarkus.http.port=9090

Run the application.




http://localhost:9090/hello

Change the code.  

package org.letustryandlearn; 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 GreetingResource { @GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return "Hello World"; } }






Run the application .
 Hit the url http://localhost:9090/hello You will get the response as "Hello World".



LET US TRY AND LEARN

Author & Editor

0 Comments:

Post a Comment