Book Image

Play Framework Cookbook

By : Alexander Reelsen
Book Image

Play Framework Cookbook

By: Alexander Reelsen

Overview of this book

<p>The Play framework is the new kid on the block of Java frameworks. By breaking with existing standards the play framework tries not to abstract away from HTTP as most web frameworks do, but tightly integrates with it. This means quite a shift for Java programmers. Understanding these concepts behind the play framework and its impact on web development with Java are crucial for fast development of applications.<br /><br />The Play Framework Cookbook starts where the beginner documentation ends. It shows you how to utilize advanced features of the Play framework &ndash; piece by piece and completely outlined with working applications!<br /><br />The reader will be taken through all layers of the Play Framework and provided with in-depth knowledge from as many examples and applications as possible. Leveraging the most from the Play framework means to think simple again in a java environment. Implement your own renderers, integrate tightly with HTTP, use existing code, improve site performance with caching and integrate with other web services and interfaces. Learn about non-functional issues like modularity or integration into production and testing environments. In order to provide the best learning experience during reading Play Framework Cookbook, almost every example is provided with source code, so you can start immediately to integrate recipes into your own play applications.</p>
Table of Contents (16 chapters)
Play Framework Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Further Information About the Play Framework
Index

Creating a new application


After installing the necessary parts to start with Play, the next step is to create a new application. If you are a Java developer you would most likely start with creating a Maven project, or alternatively create some custom directory structure and use Ant or scripts to compile your sources. Furthermore, you would likely create a WAR file which you could test in your web application server. All this is not the case with the Play framework, because you use a command line utility for many tasks dealing with your web application.

How to do it...

Change into a directory where you want to create a new application and execute the following command:

play new myApp

How it works...

This command will create a new directory named myApp and copy all needed resources for any project into it. After this is done, it should be finished in almost no time. The following file system layout exists inside the myApp directory:

./conf
./conf/dependencies.yml
./conf/routes
./conf/application.conf
./conf/messages
./test
./lib
./public
./app
./app/models
./app/controllers
./app/views

If you are familiar with a rails application, you might be able to orientate very quickly. Basically, the conf directory contains configuration and internationalization files, where as the app folder has a subdirectory for its model definitions. Its controllers contain the business logic and its views, being a mix of HTML and the Play template language. The lib directory contains jar libraries needed to run your application. The public folder contains static content like JavaScript, CSS, and images; and finally the test folder contains all types of tests.

There's more...

Generally speaking, you can add arbitrary content in the form of directories and files in the application directory; for example, the files needed to support Eclipse, or NetBeans will be put here as well. However, you should never remove data which has been copied during the creation of the application unless you really know what you are doing.

Support for various IDEs

You can add support for your IDE by entering: playeclipsify, playidealize, or playnetbeansify. Every command generates the files needed to import a Play application into your favorite IDE.