Download presentation
Presentation is loading. Please wait.
1
Play Framework: Introduction
COMP 353 Summer
2
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 Redeploy with a server In computing based on the Java Platform, JavaBeans are classes that encapsulate many objects into a single object (the bean). Any model which don't identify resource and the action associated with is restless. restless is not any term but a slang term to represent all other services that doesn't abide with the above definition. In restful model resource is identified by URL (NOUN) and the actions(VERBS) by the predefined methods in HTTP protocols i.e. GET, POST, PUT, DELETE etc.
3
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 In computer science, type safety is the extent to which a programming language discourages or prevents type errors. Full stack ; "full stack" frameworks appeared, that often gathered multiple libraries useful for web development into a single cohesive software stack for web developers to use
4
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.
5
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
6
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.
7
Layout of a Play Project
8
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
9
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 .
10
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 sub-directories for images, CSS stylesheets and JavaScript files. You should organize your static assets like this to keep all Play applications consistent.
11
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.
12
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.
13
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.
14
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.
15
Typical .gitignore file
Generated folders should be ignored by your version control system. logs project/project project/target target tmp
16
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.
17
Samples
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.