Ventuno
Setting up the Java Play Framework
I recently spent a disproportionate amount of time setting up the Java Play Framework, so wanted to document the steps in order to help anyone else in the future!
For clarity, the setup procedure here is also related to build tools, in this case Gradle/SBT/Activator and IDEs (IntelliJ CE 2016).
The Play Framework comes with it’s own build tool, based on SBT since it is a scale based tool. Activator is the name of the build tool, and it seems to work reasonably well. In trying to get the web framework setup, however, I wanted to keep the same build tool as I had on other projects, namely Gradle. It turned out, that this was a very difficult task to achieve due to some innate incompatibilities. In the end I settled with using Activator, because the process had become a bit of a time sink.
Step 1 - Install Scala Plugin
Ensure IntelliJ has the Scala Plugin installed. The Scala plugin comes with
support for the Play Framework 2.0+ (although I found that not to be the case
for the latest release). So in order to install it go to preferences ⌘ ,
. In
the plugins tab, ensure that Scala is checked. If not, check it for download
and install. You will need to restart IntelliJ.
Step 2 - Create new Project
From here follow the normal procedure for creating a new project in IntelliJ. However, choose Scala as the project type (even if you are developing in Java) and then choose Activator as the subtype.
From here you are given the opportunity to setup the project name but also a starter project brought to you from templates at Lightbend.
Step 3 - Choosing the starter template
At this point I found that my decision had a big effect on what would work. The result of my testing is that choose “Play 2.4 Java Seed” is best for my purposes. This provides you with a small template project, including some very basic application and integration tests. This was actually the main reason for wanting to use Play in the first place, since I was very underwhelmed with the testing options available for the Spark Framework.
The other thing to note, is that the choice for “Play 2.4 Java Seed” over “Play
Java Seed” was based on some incompatibility with IntelliJ, whereby a missing
symbol
error would prevent the programme compiling in IntelliJ, although it
would compile fine using Activator.
Step 4 - Run the test suite
The test suite should run fine within IntelliJ on a brand new project, since IntelliJ recognises the flags on the test folder. However, the tests here are very specific and tied to the implementation of the tutorial template, so will break as soon as you change anything.
Conclusion
I realise that this is actually a very simple tutorial, and everything seems pretty obvious. I hadn’t initially considered that it would turn out like this, but realise now that all the trouble I had, has now brought me to the point where the process is very simple.
I will continue to use the Play Framework over the coming weeks to implement my
Web TTT, and I’m sure I’ll find some other intricacies that are worth noting.
For now that, the startup is pretty plain sailing, with packages placed into
the lib/
directory being automatically added to the class path, and static
assets also managed out of the box.