You are here

Playing with Play

logoI have to spend some time on a project that will provide and use REST APIs. After a rapid comparison between Play and Spring (see below), I start with Play and Scala. I'm a beginner in Play and in Scala, so assume that information below can be naive or incorrect.

Play vs Spring

Installation

On a fresh Linux Mint 17.3 64-bit machine, following Play installation documentation:

  • download Oracle Java 8 SDK (the x64 tar.gz version)
  • unpack the tarball
  • move its contents to /usr/jdk/:
sudo mkdir /usr/jdk
sudo mv jdk1.8.0_102 /usr/jdk/
  • make it visible:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/jdk/jdk1.8.0_102/bin/java" 1
sudo update-alternatives --set java /usr/jdk/jdk1.8.0_102/bin/java
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/jdk/jdk1.8.0_102/bin/javac" 1
sudo update-alternatives --set javac /usr/jdk/jdk1.8.0_102/bin/javac
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/jdk/jdk1.8.0_102/bin/javaws" 1
sudo update-alternatives --set javaws /usr/jdk/jdk1.8.0_102/bin/javaws
  • download Activator offline distribution
  • unzip the archive
  • move its contents to ~/DevTools/
  • add its bin folder to PATH, for instance by adding following line to .bashrc:
export PATH="$HOME/DevTools/activator-dist-1.3.10/bin":$PATH
  • download IntelliJ Community Edition
  • unpack the tarball
  • move its contents to ~/DevTools/
  • add an entry to Mint menu (the command has to run idea.sh in the bin subdirectory) - Note: first start allows to add an IntelliJ entry to the menu. Didn't test this.
  • at first start, request Scala plugin installation

Proxy configuration

If you are behind a proxy, configure IntelliJ settings:

  • once a project is opened: File / Settings... / Appearance & Behaviour / System Settings / HTTP Proxy
  • File / Settings... / Build, Execution, Deployment / Build Tools / SBT: add following parameters to JVM options:
-Dhttp.proxyHost=<proxyHost> -Dhttp.proxyPort=<proxyPort> -Dhttps.proxyHost=<proxyHost> -Dhttps.proxyPort=<proxyPort>

Configure Activator as well:

  • create (or update) ~/.activator/activatorconfig.txt file:
# Proxy settings
-Dhttp.proxyHost=proxy
-Dhttp.proxyPort=8080
-Dhttps.proxyHost=proxy
-Dhttps.proxyPort=8080
# Here we configure the hosts which should not go through the proxy.  You should include your private network, if applicable.
-Dhttp.nonProxyHosts="localhost|127.0.0.1"
# These are commented out, but if you need to use authentication for your proxy, please fill these out.
#-Dhttp.proxyUser=PUT YOUR PROXY USER HERE
#-Dhttp.proxyPassword=PUT YOUR PROXY PASSWORD HERE
  • copy ~/.activator/activatorconfig.txt to ~/.sbt/jvmargs
  • add following code to line 147 of <activatorFolder>/bin/activator file (if your Activator version is 1.3.10, or if line 394: addConfigOpts: command not found error message is displayed when you start Activator):
addConfigOpts () {
  dlog "[addConfigOpts] arg = '$*'"
  for item in $*
  do
    addJava "$item"
  done
}

(references:  https://www.lightbend.com/activator/docs and https://github.com/steveswing/activator/commit/3dd59494d01d4f75a3340e5007f12daf302da051)

Hello world

  • run Activator web interface:
activator ui
  • visit localhost:8888 URL
  • for Java, select Tutorials / Play Java Intro
  • create app, play with it. This video explains what's going on under the hood.
  • for Scala, the tutorial is Play Scala Intro. Associated video.

Reference material

Play documentation

Activator and sbt

Play with Java

Play with Scala

Examples, tutorials

Next article