Hello World in Spark with SBT

The code for this post appears in this github repository.

Spark is a promising little Java web framework, suggested to me by my boss after I wrote a microservice in Play!. I believe his exact phrase was “Why?” and that the question was legitimate because Play! is heavier than you need for just spitting out JSON.

I still like SBT over just Maven, because I am lazy and do not want to have to manage my pom.xml. Spark’s tutorials assume you’re using Maven, so here’s what I did instead, just for posterity.

First, build.sbt:

The important difference from what you’d get by doing “activator init” to get a new Play! app is the last line, which tells sbt where to find the project’s main method.

I also wanted /project/plugins.sbt in order to make the “sbt eclipse” command available:

Finally, the Java source for the application:

That’s it!