The conf/ directory

Play Framework: Introduction
COMP 353
Summer 2015-16
Challenges of Java Web App
Development Today






Lots of Time waiting for server redeploys
Long, Ugly error Messages
Crazy XML Configuration
Bean Failures
RESTfull URL-s
A lot of complexity
Play Framework
 Play Framework is an open-source Web Framework
written in Java launched in 2008
 A full-stack framework: from compilation to
deployment
 Live code changes when you refresh the browser
 More friendly error messages directly in browser
 Type safety in the templates
 Cool console and build tools
 Integrated unit testing
MVC approach
 Model–view–controller (MVC) is a software
architectural pattern for implementing user interfaces.
 It divides a given software application into three
interconnected parts, so as to separate internal
representations of information from the ways that
information is presented to or accepted from the user.
 The central component of MVC, the model, captures
the behavior of the application in terms of its problem
domain, independent of the user interface. The model
directly manages the data, logic and rules of the
application.
 A view can be any output representation of
information, such as a chart or a diagram; multiple
views of the same information are possible, such as a
bar chart for management and a tabular view for
accountants.
 The third part, the controller, accepts input and
converts it to commands for the model or view
Convention over configuration
 Convention over configuration (also known as coding
by convention) is a software design paradigm which
seeks to decrease the number of decisions that
developers need to make, gaining simplicity, and not
necessarily losing flexibility.
Layout of a Play Project
The app/ directory
 The app directory contains all executable artifacts:
Java and Scala source code, templates and compiled
assets’ sources.
 There are three standard packages in the app
directory, one for each component of the MVC
architectural pattern:
 app/controllers
 app/models
 app/views
 You can add your own packages, for example an
app/utils package.
 There is also an optional directory called app/assets
for compiled assets such as LESS sources and
CoffeeScript sources .
The public/ directory
 Resources stored in the public directory are static
assets that are served directly by the Web server.
 This directory is split into three standard subdirectories for images, CSS stylesheets and
JavaScript files. You should organize your static
assets like this to keep all Play applications
consistent.
The conf/ directory
 The conf directory contains the application’s
configuration files. There are two main configuration
files:
 application.conf, the main configuration file for the
application, which contains standard configuration
parameters
 routes, the routes definition file.
 If you need to add configuration options that are
specific to your application, it’s a good idea to add
more options to the application.conf file.
 If a library needs a specific configuration file, try to file
it under the conf directory.
The lib/ directory
 The lib directory is optional and contains unmanaged
library dependencies, ie. all JAR files you want to
manually manage outside the build system. Just drop
any JAR files here and they will be added to your
application classpath.
The project/ directory
 The project directory contains the sbt build
definitions:
 plugins.sbt defines sbt plugins used by this project
 Build.scala defines your application build script.
The target/ directory
 The target directory contains everything generated by
the build system.
 classes/ contains all compiled classes (from both Java
and Scala sources).
 classes_managed/ contains only the classes that are
managed by the framework (such as the classes
generated by the router or the template system).
 resource_managed/ contains generated resources,
typically compiled assets such as LESS CSS and
CoffeeScript compilation results.
 src_managed/ contains generated sources, such as
the Scala sources generated by the template system.
Typical .gitignore file
 Generated folders should be ignored by your version
control system.





logs
project/project
project/target
target
tmp



Because Play uses UTF-8 as single encoding, it’s very important that
all text files hosted in these directories are encoded using this charset.
Make sure to configure your text editor accordingly.
Now if you’re a seasoned Java developer, you may wonder where all
the .class files go. The answer is nowhere: Play doesn’t use any class
files but reads the Java source files directly. Under the hood we use the
Eclipse compiler to compile Java sources on the fly.
That allows two very important things in the development process. The
first one is that Play will detect changes you make to any Java source
file and automatically reload them at runtime. The second is that when
a Java exception occurs, Play will create better error reports showing
you the exact source code.
Samples
 https://www.playframework.com/documentation/2.0/S
amples