Migrating from Play to the Ninja Framework

The PlayFramework has been my go-to framework of choice for several months. It stands out in the crowded space of jvm web frameworks because it is (relatively) lightweight, with a short learning curve, and a focus on ease of testing both at the unit and functional level.

So far so good. However… The core logic of the framework (version 2 and up) is mostly written in Scala, and it shows:

  • view templates have to be scripted using Scala
  • the build tooling uses SBT, instead of the Maven/Gradle alternatives favored by the majority of Java projects
  • a Scala/SBT plugin is required to compile the code in Intellij and Eclipse.
  • long build times, courtesy of the Scala compiler

These annoyances (from the standpoint of a Java programmer who is not particularly interested in writing Scala code) do add up, so much so that at times this negates the productivity gains promised by the framework.

The Ninja Framework


The Ninja framework is heavily inspired by Play, with the same focus on simplicity and performance, the same functionality (both frameworks provide the same basic constructs in terms of routers, controllers, filters…). The API is also very similar.

Above all this is a pure Java (no Scala) framework so it removes all of the concerns highlighted above.  So all in all it’s an easy trade-off.

Migrating from Play to Ninja

This should be fairly simple because the APIs of both frameworks are near identical. Amongst the salient points:

  1. create a pom.xml with Ninja framework dependencies at the root of your Play project (examples available on the NinjaFramework website)
  2. setup your project as a Maven project. In Intellij this is done with a right-click on the pom above and select “Add as a Maven project”
  3. replace all of the play.* imports by their equivalents ninja.*
  4. create a Java class to host the route configuration (instead of a property file in Play)
  5. some of the properties in the application.conf may differ from Play to Ninja – no shortcut here they have to be analysed on a case by case basis.
  6. (the best part) remove the scala cruft: scala plugin, build.scala, plugins.sbt, activators…
  7. Watch your compilation time plummet. Enjoy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s