Before installing the Play Scala module, be sure to have a working installation of Play framework. Play Scala require Play 1.2.2.
You don’t need to already have Scala installed on your computer. The Play Scala module comes with all required libraries and with the Scala compiler.
The included Scala version is 2.8.1.
Installing the Scala module locally
The simpler way to work with Play and Scala is to download and install the Scala module locally. You can use the
play install scala command to do that:
$ play install scala ~ _ _ ~ _ __ | | __ _ _ _| | ~ | '_ \| |/ _' | || |_| ~ | __/|_|\____|\__ (_) ~ |_| |__/ ~ ~ play! 1.2.2, http://www.playframework.org ~ ~ Will install scala-0.9.1 ~ This module is compatible with: Play 1.2.2 ~ Do you want to install this version (y/n)? y ~ Installing module scala-0.9... ~ ~ Fetching http://www.playframework.org/modules/scala-0.9.1.zip ~ [--------------------------100%-------------------------] 17313.2 KiB/s ~ Unzipping... ~ ~ Module scala-0.9.1 is installed!
Creating a new Scala application
Now that you have the Scala module locally installed, you can ask Play to create a new application with the Scala module enabled. Use the
play new --with scala command for that.
The --with option of the play new command allow to automatically configure a set of locally installed module during application creation.
$ play new myScalaApp --with scala ~ _ _ ~ _ __ | | __ _ _ _| | ~ | '_ \| |/ _' | || |_| ~ | __/|_|\____|\__ (_) ~ |_| |__/ ~ ~ play! 1.2.2, http://www.playframework.org ~ ~ The new application will be created in ~/myScalaApp ~ What is the application name? [myScalaApp] ~ ~ Resolving dependencies using ~/myScalaApp/conf/dependencies.yml, ~ ~ play->scala 0.9.1 (from playLocalModules) ~ ~ Installing resolved dependencies, ~ ~ modules/scala-0.9.1 -> ~/play/1.2/modules/scala-0.9.1 ~ ~ OK, the application is created. ~ Start it with : play run myScalaApp ~ Have fun! ~
As you see, the conf/dependencies.yml dependencies configuration file is automatically configured with the Scala dependency:
# Application dependencies require: - play - play -> scala 0.9.1
Starting a Scala application
Like for any other Play application, you simply start your newly created application by typing
$ play run myScalaApp ~ _ _ ~ _ __ | | __ _ _ _| | ~ | '_ \| |/ _' | || |_| ~ | __/|_|\____|\__ (_) ~ |_| |__/ ~ ~ play! 1.2.2, http://www.playframework.org ~ ~ Ctrl+C to stop ~ Listening for transport dt_socket at address: 8000 21:26:14,344 INFO ~ Starting ~/myScalaApp 21:26:14,351 INFO ~ Module scala is available (~/play/1.2/modules/scala-0.9) 21:26:16,091 WARN ~ You're running Play! in DEV mode 21:26:16,170 INFO ~ Listening for HTTP on port 9000 ... 21:26:29,177 INFO ~ Application 'myScalaApp' is now started !
Now that you have successfully enabled Scala support for your Play installation you can start by creating your first application.