Published on

Hello World Web App with Java Springboot and Maven


In this post we will setup a Java Hello World Web App, using Maven and SpringBoot on Ubuntu 16. I will create all the needed files in this tutorial, but you can head to to generate the zip for you.

Setup Java

Setup Java 1.8:

$ apt update
$ apt install wget openssl vim software-properties-common -y
$ add-apt-repository ppa:webupd8team/java -y
$ apt-key adv --keyserver --recv-keys C2518248EEA14886
$ apt update && apt install oracle-java8-installer -y

Ensure that Java is installed:

$ java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

Install Apache Maven:

Maven is a build automation tool used primarily for Java projects. Let's setup Maven:

$ cd /opt
$ curl -SL | tar -xz
$ mv apache-maven-3.5.4 maven
$ echo 'M2_HOME=/opt/maven' > /etc/profile.d/
$ echo 'export PATH=${M2_HOME}/bin:${PATH}' >> /etc/profile.d/
$ chmod +x /etc/profile.d/
$ source /etc/profile.d/

Verify that Maven is installed:

$ mvn -version
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T18:33:14Z)
Maven home: /opt/maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "4.9.87-linuxkit-aufs", arch: "amd64", family: "unix"

Setup the Application:

Create the home directory:

$ mkdir myapp && cd myapp

Create the directory structure:

$ mkdir -p src/main/java/hello

Create and Edit the pom.xml:

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







Create the Main Application Class:

package hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class MainApplicationClass {

    public static void main(String[] args) {, args);

Create the Route Controller:

package hello;

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

public class HelloController {

        public String index() {
	    return "This is the index!\n";
        public String index2() {

	    return "Hello, World!\n";


Build and Compile:

This will download all the dependencies and build the jar file:

$ mvn clean package

Start and Test the Application:

Run the application:

$ java -jar target/myapp-1.0.jar
2018-08-03 12:31:06.967  INFO 5594 --- [           main] hello.MainApplicationClass               : Started MainApplicationClass in 3.656 seconds (JVM running for 4.243)

Test the Application:

$ curl http://localhost:8080/
This is the index!

And for our /hello route:

$ curl http://localhost:8080/hello
Hello, World!

Thank You

Thanks for reading, feel free to check out my website, and subscrube to my newsletter or follow me at @ruanbekker on Twitter.

Buy Me A Coffee