As the demand for cloud-native and container-ready applications rises, Java professionals are increasingly turning to Quarkus for building lightweight, efficient applications that integrate seamlessly with Kubernetes. Starting your first Quarkus project might seem daunting, but with this step-by-step guide, setting up a first Quarkus project is straightforward, especially for Java developers already familiar with traditional frameworks. Quarkus’s features like live reload, fast startup time, and native image support make it an ideal choice for modern Java applications, offering powerful tools for both development and deployment.


Why Choose Quarkus for Java Development?

Before diving into the setup, let’s explore why Quarkus has gained popularity among Java developers worldwide:

  1. Optimized for Containers
    Quarkus is specifically designed for containerized environments, ensuring low memory usage and fast boot times, which are essential for cloud deployments.
  2. Native Image Support with GraalVM
    Quarkus can compile Java applications to native binaries using GraalVM, which provides faster execution times and lower memory consumption.
  3. Developer Productivity
    With live reload features and simplified dependency management, Quarkus allows developers to focus on coding without interruptions.
  4. Kubernetes and Microservices-Friendly
    Quarkus offers out-of-the-box integration with Kubernetes, making it a strong choice for microservices architectures, especially when coupled with frameworks like Eclipse MicroProfile.

Setting Up Your First Quarkus Project: Prerequisites

Before setting up your first Quarkus project, make sure you have:

  1. Java Development Kit (JDK)
    Quarkus requires JDK 11 or higher. Install OpenJDK if you haven’t already.
  2. Apache Maven
    Quarkus uses Maven for build management. You can download it from Maven’s official site.
  3. Integrated Development Environment (IDE)
    Quarkus works well with popular IDEs like IntelliJ IDEA, Eclipse, and Visual Studio Code. Make sure your IDE supports Maven projects for smooth configuration.

Step 1: Create a New Quarkus Project with Maven

To create your first Quarkus project, open a terminal and use the following Maven command:

mvn io.quarkus:quarkus-maven-plugin:create \
    -DprojectGroupId=com.example \
    -DprojectArtifactId=my-first-quarkus-project \
    -DclassName="com.example.GreetingResource" \
    -Dpath="/hello"

This command initializes a Quarkus project with a basic REST endpoint at /hello. Replace the projectGroupId and projectArtifactId with your desired project details.


Step 2: Understand the Project Structure

Quarkus generates a structured project with the following key folders:

  • src/main/java: Contains your application code.
  • src/main/resources: Houses configuration files and other resources.
  • src/test: Contains your test files.
  • pom.xml: The Maven file for managing dependencies.

Quarkus also generates example code, which you can modify to fit your application’s requirements.


Step 3: Run the Quarkus Application in Dev Mode

Quarkus’s Dev Mode allows live coding, meaning changes are automatically reflected in the running application without restarting. Use the command below to start your application in Dev Mode:

./mvnw compile quarkus:dev

This starts the server on http://localhost:8080. Visit http://localhost:8080/hello in your browser to see the default message from the application.

Step 4: Modify the Greeting Resource

Let’s modify the GreetingResource.java class to customize the message. Open GreetingResource.java (located in src/main/java/com/example) and change the hello() method as shown below:

Java
@Path("/hello")
public class GreetingResource {

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

This simple change customizes the message to “Hello, Quarkus World!” Save the file and refresh the /hello endpoint in your browser. Thanks to Quarkus’s Dev Mode, you’ll see the updated message immediately without restarting the server.


Step 5: Adding a Dependency

Incorporating dependencies in Quarkus is straightforward with Maven. For instance, let’s add RESTEasy Jackson for JSON processing.

  1. Open your pom.xml file.
  2. Add the following dependency:
XML
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
  1. Save pom.xml. Quarkus will reload the project automatically in Dev Mode.

Step 6: Build a Native Image with GraalVM

A standout feature of Quarkus is the ability to compile applications to native images using GraalVM, making them incredibly lightweight and fast. To build a native image:

  1. Ensure GraalVM is installed and configured.
  2. Run the following command in your terminal:
./mvnw package -Pnative

Once complete, this creates an executable in the target/ folder, which can be deployed in a containerized environment with minimal resource usage.


Deploying Quarkus in Kubernetes

Deploying Quarkus applications on Kubernetes is simplified with tools provided by Quarkus. To deploy, follow these steps:

  1. Generate Kubernetes Manifests
    Use Quarkus to auto-generate Kubernetes manifests: ./mvnw package -Dquarkus.kubernetes.deploy=true
  2. Deploy to Kubernetes
    With the manifests generated, use the following command to deploy: kubectl apply -f target/kubernetes/kubernetes.yml

This deploys your Quarkus application in Kubernetes, leveraging features like scaling, monitoring, and health checks.


10 Frequently Asked Questions (FAQs) about Quarkus

  1. What is Quarkus?
    Quarkus is a Kubernetes-native Java framework optimized for containerized environments, offering fast startup times and low memory usage.
  2. Why should I choose Quarkus for cloud-native applications?
    Quarkus supports fast startup, low memory usage, native image compilation, and seamless integration with Kubernetes, making it ideal for cloud-native Java applications.
  3. What Java version does Quarkus support?
    Quarkus requires Java 11 or higher to operate effectively.
  4. Can I use Quarkus with existing Java libraries?
    Yes, Quarkus is compatible with popular Java libraries like Hibernate ORM, RESTEasy, and Eclipse MicroProfile.
  5. What is Quarkus Dev Mode?
    Dev Mode in Quarkus allows live coding, where changes are reflected in the running application without restarting.
  6. What is GraalVM, and why is it used in Quarkus?
    GraalVM enables Quarkus to compile applications into native images, improving performance by reducing memory consumption and startup times.
  7. How does Quarkus support microservices?
    Quarkus provides full support for REST APIs, reactive programming, and container-first principles, making it ideal for microservices.
  8. How can I deploy Quarkus applications on Kubernetes?
    Quarkus provides Kubernetes integration, automatically generating manifests and simplifying deployments.
  9. Does Quarkus support reactive programming?
    Yes, Quarkus has reactive programming support, allowing non-blocking, event-driven applications.
  10. What IDEs are best for Quarkus development?
    Quarkus works well with IDEs like IntelliJ IDEA, Eclipse, and Visual Studio Code, especially those supporting Maven projects.

External Resources

  1. Quarkus Official Documentation – A comprehensive guide to getting started with Quarkus and its features.
  2. GraalVM Documentation – Learn about GraalVM and its native image capabilities.
  3. Kubernetes Documentation – Resources and guides on deploying applications in Kubernetes.

Conclusion

Setting up your first Quarkus project introduces you to a framework designed to make Java viable for the cloud-native and microservices era. With Quarkus, Java developers can leverage the benefits of containerization, Kubernetes integration, and reactive programming, delivering applications that start fast, consume fewer resources, and scale effectively. From Dev Mode to native image support, Quarkus equips Java professionals with tools to optimize productivity and application performance in modern, containerized environments.