Book Image

Play Framework Cookbook - Second Edition

By : Alexander Reelsen, Giancarlo Inductivo
Book Image

Play Framework Cookbook - Second Edition

By: Alexander Reelsen, Giancarlo Inductivo

Overview of this book

<p>As web and mobile systems become more sophisticated, anchoring systems in a mature, solid framework has become increasingly important. Play 2 provides developers with the necessary tools to build robust web applications.</p> <p>This book is a compilation of useful recipes aimed at helping developers discover the power of Play 2. The introductory section serves as a primer to Play Framework, wherein all the fundamentals of the framework are covered extensively. It then explains the usage of controllers and how modules can be leveraged for optimal performance. Next, the book walks you through creating and using APIs, followed by extensive real-world applications. Finally, you will learn to manage applications post production.</p>
Table of Contents (15 chapters)
Play Framework Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a Play application using Typesafe Activator


Once you have a JDK and Activator installed and properly configured, you should be ready to create Play 2.3.x applications. Beginning with Play 2.0, developers are now able to create Java- or Scala-based Play applications. Activator provides many Play project templates for both Java and Scala. For the first project, let us use the basic project templates. We will also be using the command-line interface of Activator across all recipes in this cookbook.

How to do it...

You need to perform the following for creating the templates for both Java and Scala:

  • For Java, let's use the play-java template and call our first application foo_java by using the following command:

        $ activator new foo_java play-java
    
  • For Scala, let's use the play-scala template and call our first application foo_scala by using the following command:

        $ activator new foo_scala play-scala
    

How it works…

This Activator command creates the project's root directory (foo_java or foo_scala) and creates all the relevant subdirectories, config files, and class files:

The following screenshot shows the root directory for foo_java:

The following screenshot shows the root directory for foo_scala:

As you notice, both the Java and Scala project template generated an almost identical list of files, except for class files that are generated as .java files for the play_java template and as.scala files for the play_scala template.

For the project's directory structure, one of the more important aspects of Play Framework is its adherence to the concept of convention over configuration. This is best reflected by the standard project directory structure of every Play application it follows:

1st Level

2nd Level

3rd Level

Description

app/

  

Application source files

 

assets/

 

Compiled JavaScript or style sheets

  

stylesheets/

Compiled style sheet (such as LESS or SASS)

  

javascripts/

Compiled JavaScript (such as CoffeeScript)

 

controllers/

 

Application request-response controllers

 

models/

 

Application domain objects

 

views/

 

Application presentation views

conf/

  

Application configuration files

public/

  

Publicly available assets

 

stylesheets/

 

Publicly available style sheet files

 

javascripts/

 

Publicly available JavaScript files

project/

  

Build configuration files (such as Build.scala and plugins.sbt)

lib/

  

Unmanaged libraries and packages

logs/

  

Log files

test/

  

Test source files

Source code, configuration files, and web assets are organized in a predefined directory structure, making it easy for the developer to navigate through the project directory tree and find relevant files in logical placements.

There's more...

Go to http://typesafe.com/activator/templates for a comprehensive list of available project templates.