Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Jump into Java microframeworks, Part 1

Matthew Tyson | Oct. 28, 2015
Go extra lightweight, with Java microframeworks Spark, Ninja, and Play

java microframeworksp1 fig8
Figure 8. Add templates to source in Eclipse

Run the app

As our final step, stop App.java and run it again. View the http://localhost:4567/thyme location and you'll see one of the greats of Rock and Roll's second generation displayed.

You might observe that it took a little more doing to engage the templating library in Spark than in Ninja. That is because Spark includes fewer libraries out of the box, and allows a broader choice for templating solutions. Spark is extremely lean, and is ideal for creating small RESTful APIs or small web apps with a variety of front-end technology choices.

Play: The first microframework for Java and Scala

We've sailed through short demos for Ninja and Spark, and now I personally am excited to take a look at Play, the venerable grandfather of the group. Play is known as a Scala framework, but it's also a high quality Java microframework, based on the same RVC model as the others profiled here.

Installing Play is different from the others, because you need to first download and install Typesafe Activator (there are other ways, but this is the easiest). Unlike the other two microframeworks profiled here, Play offers a complete replacement to Java tooling like Maven, so you'll find you have to learn more conventions to use it effectively.

For the download, the minimal version should be fine. Note that it will resolve dependencies for you. To install it, unzip Activator into a directory and put it on your system path.

Next, create a new project, by typing the following at the command-line: activator new micro-play play-java. This will build a simple Java project we can use to start from, called "micro-play".

Activator timeouts

I have observed Typesafe Activator timeouts while resolving dependencies in Play. In my experience, it works to just re-run the command, even if it takes several attempts.

Now cd into your project (/micro-play) and run the interactive console by typing activator. We can run it with run. This starts our app in dev mode, with auto update enabled. You can now see it running at: http://localhost:9000/. (Sometimes it takes a minute or two to be ready, but after that changes are loaded on the fly.)

You can edit your project files with Notepad++ or VI, but I usually like to use an IDE like Eclipse. It used to be possible to run activator eclipse out of the box, but now you have to update the build config – or you can just run the UI and do it there. We'll take that approach.

 

Previous Page  1  2  3  4  5  6  7  8  9  10  Next Page 

Sign up for CIO Asia eNewsletters.