You will learn to create a simple spark API in maven. Spark – A micro-framework for creating web applications in Kotlin and Java 8 with minimal effort. Make sure maven is installed by running mvn --version in the terminal/command prompt. I will build a website registry app, which stores websites information in a HashMap (in-memory database). This is an example app, used in later references.

Steps to create a Spark app in Maven

Step – 1
Download the tutorial content from above link, extract the zip. You will see spark-api-example . This is generated using the below command, but you don’t need to run the command.

mvn -B archetype:generate -DgroupId=com.jstobigdata.maventutorial \
  -DartifactId=spark-api-example \
  -Dpackage=com.jstobigdata.maventutorial \

Step – 2
I converted the project spark-api-example to an eclipse project by running the command below. You don’t have to run it.

cd spark-api-example && mvn eclipse:eclipse

Step – 3
Now open the project in Eclipse or STS. You can download these IDE from the respective sites, alternatively, you can also use IntelliJ. Launch the STS/Eclipse, select a workspace, then click OK. After that, right-click on the package explorer, General, Existing projects into Workspace, click next, select the spark-api-example and then next, finish. This will import the project into your workspace.

Step – 4
Run mvn clean install inside the spark-api-example . Now right-click on and run it as Java Application. Now the app is up and running on http://localhost:8090/.

Step – 5
Execute the following cURL commands to make sure sample data gets added.

curl -X GET http://localhost:8090/

Add a few records.

curl -X POST \

List websites.

curl -X GET \

The idea is to understand how maven is used, how dependencies are added in the pom.xml, and what is the plugin that is added.

<project xmlns=""








Keep this handy as I will be referring back to this example again and again.

By |Last Updated: July 31st, 2019|Categories: Java™, Maven|

Table of Contents