Installing Micronaut CLI and Setting Up Your First Project

Micronaut is a modern JVM-based framework designed to create lightweight, fast, and cloud-native microservices. In this post, we’ll walk you on installing Micronaut CLI and creating your very first Micronaut project. No complex termsβ€”just a simple and clear guide to get you started!

Installing Micronaut CLI and Setting Up Your First Project

πŸ› οΈ What You Need in Installing Micronaut CLI

Before we start, make sure you have the following installed on your machine:

  • Java 17 or later. I am using Java 21
  • Micronaut CLI (You can install it using SDKMAN or your OS package manager)
  • A code editor (like VS Code or IntelliJ IDEA)

πŸ“ Step 1: Create a New Project

Open your terminal and run the following command:


mn create-app com.kscodes.micronaut.helloworld


This command will:

  • Create a new project using Micronaut CLI
  • By default it will create a gradle project.
  • If you need a maven project then use below command

mn create-app com.kscodes.micronaut.helloworld --build=maven --lang=java
  • Set the base package to com.kscodes.micronaut.helloworld

After this, navigate into the project directory:


cd helloworld

πŸ—‚οΈ Step 2: Project Structure Overview

Your project will have the following structure:


helloworld/
 β”œβ”€β”€ src/
 β”‚   └── main/
 β”‚       └── java/
 β”‚           └── com/kscodes/micronaut/helloworld/
 β”‚               └── Application.java
 β”‚
 β”œβ”€β”€ application.yml
 └── build.gradle (or pom.xml)

✍️ Step 3: Create a Controller

Now, add a simple REST controller.

Create a new file:
src/main/java/com/kscodes/micronaut/helloworld/HelloController.java


package com.kscodes.micronaut.helloworld;

import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;

@Controller("/hello")
public class HelloController {

    @Get("/")
    public String sayHello() {
        return "Hello from KSCodes. Welcome to my First Micronaut App!";
    }
}

This controller handles HTTP GET requests to /hello.

A mvnw.bat will be created inside the helloworld folder. Go to that folder and then execute the below command.

▢️ Step 4: Run the Application


mvnw mn:run

🌐 Step 5: Test Your Endpoint

Open your browser or a tool like Postman and visit:

http://localhost:8080/hello

You should see this message:

Installing Micronaut CLI and Setting Up Your First Project

βœ… Summary

In this tutorial, you:

  • Created a Micronaut project using CLI
  • Used Java with the com.kscodes.micronaut package
  • Built and tested a simple controller

Micronaut makes it easy to start quickly, with minimal setup and fast performance.