Quarkus - Qute - Hello World Example

Hello everyone, today we will learn how to develop a Quarkus web application, using Qute Template engine.


 Following technologies stack being used:
  • JDK 11
  • Qute 2.2.3.Final
  • Quarkus 2.2.3.Final
  • Maven

Project Structure



Dependency management - Maven[pom.xml]

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>quarkus-freemarker-helloworld</artifactId>
<version>1.0.0-SNAPSHOT</version>
<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-plugin.version>2.2.3.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom
</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.2.3.Final</quarkus.platform.version>
<surefire-plugin.version>2.22.1</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>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute</artifactId>
</dependency>

<
dependency>
<
groupId>io.quarkus</groupId>
<
artifactId>quarkus-arc</artifactId>
</
dependency>
<
dependency>
<
groupId>io.quarkus</groupId>
<
artifactId>quarkus-resteasy</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>
<
build>
<
plugins>
<
plugin>
<
groupId>io.quarkus</groupId>
<
artifactId>quarkus-maven-plugin</artifactId>
<
version>${quarkus-plugin.version}</version>
<
executions>
<
execution>
<
goals>
<
goal>build</goal>
</
goals>
</
execution>
</
executions>
</
plugin>
<
plugin>
<
artifactId>maven-compiler-plugin</artifactId>
<
version>${compiler-plugin.version}</version>
</
plugin>
<
plugin>
<
artifactId>maven-surefire-plugin</artifactId>
<
version>${surefire-plugin.version}</version>
<
configuration>
<
systemProperties>
<
java.util.logging.manager>
org.jboss.logmanager.LogManager
</
java.util.logging.manager>
</
systemProperties>
</
configuration>
</
plugin>
</
plugins>
</
build>
<
profiles>
<
profile>
<
id>native</id>
<
activation>
<
property>
<
name>native</name>
</
property>
</
activation>
<
build>
<
plugins>
<
plugin>
<
artifactId>maven-failsafe-plugin</artifactId>
<
version>${surefire-plugin.version}</version>
<
executions>
<
execution>
<
goals>
<
goal>integration-test</goal>
<
goal>verify</goal>
</
goals>
<
configuration>
<
systemProperties>
<
native.image.path>
${project.build.directory}/${project.build.finalName}-runner
</
native.image.path>
</
systemProperties>
</
configuration>
</
execution>
</
executions>
</
plugin>
</
plugins>
</
build>
<
properties>
<
quarkus.package.type>native</quarkus.package.type>
</
properties>
</
profile>
</
profiles>
</
project>


HelloResource.java

package org.acme;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;

@Path("/")
public class HelloResource {

@Inject
Template index;

@GET
@Produces(MediaType.TEXT_HTML)
public TemplateInstance get() {
return index.data("name", "knowledgefactory");
}

}


View(index.html)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Qute Hello World</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

</head>
<body>
<div class="container">
<div class="jumbotron">
<h3>Greetings from {name}</h3>
</div>
</div>
</body>
</html>


Run the Application

Build application jar file: mvn clean package


Start application: java -jar quarkus-run.jar

Open the browser and hit the endpoint http://localhost:8080/

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete