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)
    • You can download it from micronaut website.
    • Unzip the downloaded zip file into your system
    • Create the MICRONAUT_HOME environment variable with the installation directory path and also update the PATH variable so that it gets reflected correctly.
  • A code editor (like VS Code or IntelliJ IDEA)

πŸ“ Step 1: Create a New Project

Open your terminal and run the following command:

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
  • Set the base package to com.kscodes.micronaut.helloworld

After this, navigate into the project directory:

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

Your project will have the following structure:

✍️ Step 3: Create a Controller

Now, add a simple REST controller.

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

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

🌐 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.