Getting Started / Installing Scala Play! Framework 2016

The instructions have changed a bit for starting with the Play! Framework for the first time so here I revisit how to get it working for the first time.

Installing Play / Activator
Go to the Scala Play site here:
https://www.playframework.com/download

Download this version of Activator:
https://downloads.typesafe.com/typesafe-activator/1.3.10/typesafe-activator-1.3.10-minimal.zip

Create a folder, e.g.

mkdir ~/activator

Change to that directory and unzip the typesafe-activator-1.3.10-minimal.zip file into it.

Add Activator to your PATH

Add to the PATH in .bashrc or .bash_profile

 export PATH=$PATH:/home/me/activator/activator-1.3.10-minimal/bin

Creating a Play Project
Create a containing folder, not per Play instructions but just to keep things separate.

mkdir /home/me/scala-play-test
 cd /home/me/scala-play-test

In this folder run activator to create the actual project:
activator new scala-play-test play-scala

Wait while activator downloads all of its dependencies and creates the files and folders for the project.

Change into the directory created by activator:

cd ./scala-play-test

 

Starting the application
From the new project folder run the following:

activator run

Eventually activator the web server should start on port 9000, with output like this:

[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

Launch the following URL in your browser:
http://localhost:9000/

You should get a page like this:

Screen Shot 2016-05-28 at 22.14.03

With activator running edit the following file:

 app/controllers/HomeController.scala

It should look like this:

package controllers

import javax.inject._
import play.api._
import play.api.mvc._

/**
 * This controller creates an `Action` to handle HTTP requests to the
 * application's home page.
 */
 @Singleton
 class HomeController @Inject() extends Controller {
  
 /**
  * Create an Action to render an HTML page with a welcome message.
  * The configuration in the `routes` file means that this method
  * will be called when the application receives a `GET` request with
  * a path of `/`.
  */
  def index = Action {
  Ok(views.html.index("Your new application is ready."))
  }

}

Change the line

Ok(views.html.index("Your new application is ready!"))

to this:

Ok("Hello, World!")

Refresh the page in your browser.

The page should now look like this:

Screen Shot 2016-05-28 at 22.22.51.png

At this point we have a working application that we can edit and see the changes as we make them.

Next Steps
This is where the tutorial ends but the next step is probably to get activator to generate the files needed by your IDE, usually eclipse or intelliJ.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s