Springboot Web Hello World with a Java & Pom.xml file

This blog presents instructions on how to quickly get started with Springboot Hello World with just one Java file and a Pom.xml.

Before getting set up with files, make sure you have installed and configured following

  • Java; Setup Java_Home as it is required by maven
  • Maven; Maven would be used to package our app.


Java Code Sample

Following is the code for Java file. Make sure to create hello/HelloController.java file within src/main/java. This is required for maven to package it correctly.

package hello;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

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

public class HelloController {

    String home() {
        return "Hello World!";

    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloController.class, args);



Code Sample for POM.xml

Following is the code for pom.xml. Make sure to put pom.xml at the topmost level (along side src folder)

<?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">

	    <!-- The main class to start by executing java -jar -->

    <!-- Additional lines to be added here... -->
Package and Run the App

Once you have created the file, execute the following command to run the code:

mvn package
java -jar target/SpringBootSampleWeb-0.0.1.jar
Ajitesh Kumar
Follow me

Leave A Reply

Time limit is exhausted. Please reload the CAPTCHA.