Easy to create and run a simple Spring Boot application from the browser using Spring Boot CLI & Maven Opensource tools

Last week I was spending sometime on how to work on Spring Boot framework and Maven. 

The main goal of the Spring Boot framework is to reduce overall development time and increase efficiency by having a default setup for unit and integration tests. The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform. 

The Spring Boot CLI is a command line tool that you can use if you want to quickly develop a Spring application. It lets you run Groovy scripts, which means that you have a familiar Java-like syntax without so much boilerplate code. You can also bootstrap a new project or write your own command for it.

Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project. 

To work on the below mentioned steps, the main prerequisites are

1) JDK installed

2) Spring Boot CLI tool (https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/2.4.3/spring-boot-cli-2.4.3-bin.zip)

3) Maven tool (https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip)

Also, please make sure to setup the JAVA_HOME, PATH, etc settings in the System's environment variables.











After making the above changes, better restart the system before we perform the simple steps.

1) Create a folder called: SpringBootDemo [eg: D:\SpringBootDemo]

2) Add a file: pom.xml with the below xml code

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>net.javacode</groupId>

    <artifactId>spring-boot-hello-world</artifactId>

    <version>1.0.0</version>

    <parent>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-parent</artifactId>

        <version>2.0.3.RELEASE</version>

    </parent>

    <dependencies>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

    </dependencies>

      <build>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

        </plugins>

    </build>  

</project>

3) Create a folder structure src\main\java\net\javacode in the above folder [eg: D:\SpringBootDemo\src\main\java\net\javacode]

4) Create a java file: SpringBootHelloWorld.java and have the below code

package net.javacode;

import org.springframework.boot.*;

import org.springframework.boot.autoconfigure.*;

import org.springframework.web.bind.annotation.*;

@RestController

@EnableAutoConfiguration

public class SpringBootHelloWorld {

    @RequestMapping("/")

    String home() {

        return "<b><h1>Hello World Spring Boot!</h1></b>";

    }

    public static void main(String[] args) throws Exception {

        SpringApplication.run(SpringBootHelloWorld.class, args);

    }

}

5) Now it is the time to compile and run this code. Go to the above folder path from command line and run the maven command like below.

D:\SpringBootDemo>mvn spring-boot:run

The main goal of spring-boot:run tells Maven to compile the project and launch Spring Boot. If the compilation is successful, you can see the logo of Spring Boot appears and we can see the localhost  with 8080












Open the browser and type => http://localhost:8080 and we can see the welcome message from the spring boot application deployed on Tomcat.









Based on this exercise, we can extend our Spring Boot knowledge by exploring more :) :)

References:

1) https://maven.apache.org/

2) https://spring.io/projects/spring-boot

3) Google

Popular posts from this blog

Connecting Claude to Pega Infinity 25.1.3 via MCP — Step-by-Step

itextpdf API to generate PDF doc from an image file using Pega PE

Understanding of Hugging Face platform for AI/ML platform