Monday, 2 January 2023

Micronaut: Hello world application using Micronaut CLI

Prerequiste

Setup Micronaut CLI

 

Step 1: Open terminal and execute below command to create a Maven-based project.

mn create-app hello-world --build maven

 

Generated project structure looks like below.

bash-3.2$ tree
.
|____hello-world
| |____pom.xml
| |____README.md
| |____.gitignore
| |____.mvn
| | |____wrapper
| | | |____MavenWrapperDownloader.java
| | | |____maven-wrapper.properties
| | | |____maven-wrapper.jar
| |____mvnw
| |____micronaut-cli.yml
| |____mvnw.bat
| |____src
| | |____test
| | | |____java
| | | | |____hello
| | | | | |____world
| | | | | | |____HelloWorldTest.java
| | |____main
| | | |____resources
| | | | |____logback.xml
| | | | |____application.yml
| | | |____java
| | | | |____hello
| | | | | |____world
| | | | | | |____Application.java

 

Step 2: Navigate to hello-world folder (where pom.xml is located) and execute below command to run the application.

./mvnw mn:run

$ ./mvnw mn:run
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< hello.world:hello-world >-----------------------
[INFO] Building hello-world 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> micronaut-maven-plugin:3.4.0:run (default-cli) > process-classes @ hello-world >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ hello-world ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ hello-world ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/krishna/Documents/technical-documents/micronaut/examples/hello-world/target/classes
[INFO] 
[INFO] <<< micronaut-maven-plugin:3.4.0:run (default-cli) < process-classes @ hello-world <<<
[INFO] 
[INFO] 
[INFO] --- micronaut-maven-plugin:3.4.0:run (default-cli) @ hello-world ---
 __  __ _                                  _   
|  \/  (_) ___ _ __ ___  _ __   __ _ _   _| |_ 
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| |  | | | (__| | | (_) | | | | (_| | |_| | |_ 
|_|  |_|_|\___|_|  \___/|_| |_|\__,_|\__,_|\__|
  Micronaut (v3.7.0)

16:28:50.547 [main] INFO  io.micronaut.runtime.Micronaut - Startup completed in 633ms. Server Running: http://localhost:8080

 

Upon successful command execution, open the url in ‘http://localhost:8080’ in browser.

 



You can download this application from this link. In my next post, I will explain how to create a Rest API.

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment