SparkJava

A minimalist framework for Java Web Apps

The Spark framework for Java is a minimalist framework for building webapps in Java.

It is sometimes called SparkJava to differentiate it from the popular cluster computing platform called Apache Spark, with which it has nothing in common except the name “Spark”.

You can read more about SparkJava at:

Reviews of SparkJava and comparisons with other frameworks

Getting Started with SparkJava locally

The standard tutorial for getting started with SparkJava assumes familiarity with a few things that you may not already know about, including these:

So, I’ve created my own tutorial that starts from first principles and tries to explain these things along the way.

That tutorial can be found here: SparkJava: Getting Started

Getting Started with SparkJava on Heroku

The following repos are fairly minimal working webapps that run successfully on Heroku.

The key elements that you need are:

There are several tutorials for getting started with SparkJava on Heroku:

Why SparkJava, and not Servlets, JSP, Spring, etc.?

Java was the language of choice for some of the earliest enterprise level web applications. The Java Servlet API, combined with Java Server Pages, was the basis of many large-scale web applications that are still in use today.

Writing web applications using Java Servlets can be a tedious undertaking with a steep learning curve. The very first book in the O’Reilly Head First series was a book on this topic, with the unwieldy full title:

Head First Servlets and JSP: Passing the Sun Certified Web Component Developer Exam

That book is now in its 2nd edition

Various frameworks arose to try to simplify the process, including the popular Spring framework for dependency injection.

All of these frameworks, however, have a steep learning curve. To get even the simplest application running, i.e. a “Hello World” that simply prints “Hello World” on the root page of the application, requires an elaborate set up of several files, including an XML deployment descriptor, a specific set of directories, configuring a servlet container, etc.

With SparkJava, by contrast, with a single source code file (and a proper Maven environment to download the dependencies), you are off and running. The servlet container is built in to the framework, so there is no separate configuration.

More Advanced SparkJava Tutorials

Spark is, according to its website (quote retrieved on 6/20/2016):

A micro framework for creating web applications in Java 8 with minimal effort

You can read more about SparkJava at:

SparkJava != Apache Spark

Spark is sometimes called SparkJava to differentiate it from the popular cluster computing platform called Apache Spark, with which it has nothing in common except the name “Spark”.

References

Tutorials:

Note on the “unofficial” javadoc link above

Annoyingly, the Spark Java project doesn’t maintain up-to-date javadoc online. Instead, they invite the user to

To save you (and me) the trouble the next time we just want to look something up, I forked the repo https://github.com/perwendel/spark to https://github.com/UCSB-CS56-pconrad/spark on 06/20/2016, ran mvn javadoc:javadoc, updated the .gitignore to not ignore /target/site/apidocs, and then commited the result to a gh-pages branch. So now, you can see the generated javadoc here:

https://ucsb-cs56-pconrad.github.io/spark/target/site/apidocs/index.html

More on SparkJava