Playframework(12)More Samples and Deployment

Playframework(12)More Samples and Deployment
My first sample is todolist.

Hello World
The second simple example is hello world from the location
>pwd
/opt/play/samples/scala/helloworld
>cd /opt/play/samples/scala/helloworld
>play eclipsify

Import this project to eclipse and study. It is all about controller/action/routers/forms.

But I do not quite understand the test part, extends Specification.
org.specs2.mutable._

Computer Database
A basic CRUD application with JDBC database.
1. Anorm in Scala to visit the database, computer and company
2. list pagination and CRUD forms
3. CSS with twitter bootstrap. http://twitter.github.com/bootstrap/

Forms
Complex forms with validation

Change the router to mapping to different controller.

Change the action path to merge the different html template in different categories.

ZenTasks
Integrate authentication and security
Use AJAX and JavaScript reverse routing.

CometClock
create a Comet connection
write custom Enumerators

WebSocket chat
WebSocket connections
Advanced Akka Usage

MozWebSocket is for firefox.

Comet monitoring
advanced usage of enumerators and enumeratees

After go through all the samples codes. It seems that play is much more like MVC framework. And it has the Oauth, openID, template engine and a lot of other things. And it can also iterate with akka.

Spray is just a punch of tools, spray-IO, spray-CAN, spray-routing. I think it is more like a small and scala version of play.

5 How to deploy play framework application
5.1 Deploying your application(Based on Source Version)
Using the start command
play>start

or

>play start

It is based on standard Netty.

Using the stage task
>play clean compile stage

And everything will be in the place target/staged. And we can start the server with another command
>target/start

But my project does not work, because the Error Message:
Oops, cannot start the server.
PlayException: Database 'default' needs evolution! [An SQL script need to be run on your database.]

Solution:
For command play start, we need add a parameter
>play -DapplyEvolutions.default=true start

For the stage command
>target/start -DapplyEvolutions.default=true

5.2 Creating a standalone version of your application(Based on Binary version)
play>dist

It will create a binary file under /Users/carl/work/play/todolist/dist named todolist-1.0-SNAPSHOT.zip.

If we want to add a configuration file, we need to run like this.
>play -Dconfig.file=/Users/carl/work/play/todolist/conf/application.conf dist

Publishing to a Maven(or Ivy) repository
play>publish
project/Build.scala will be mostly like this, but I did not try.

val main = PlayProject(appName, appVersion, appDependencies).settings(
     publishTo :=Some(
          "My resolver" at "http://mycompany.com/repo"
     )

     credentials += Credentials(
          "Repo", "http://mycompany.com/repo", "admin", "password"
     )
)

5.3. Additional Configuration
Specifying the HTTP server address and port

>start -Dhttp.port=1234 -Dhttp.address=127.0.0.1

Specifying additional JVM arguments
>start -Xms128M -Xmx512m -server

Specifying alternative configuration file
>start -Dconfig.resource=prod.conf

>start -Dconfig.file=/opt/conf/prod.conf

>start -Dconfig.url=http://conf.mycompany.cm/conf/prod.conf

Overriding specific configuration keys
…snip…

Changing the log back configuration file
>start -Dlogger.resource=conf/prod-logger.xml

>start -Dlogger.file=/opt/prod/logger.xml

>start -Dlogger.url=http://conf.mycompany.com/logger.xml

5.5 Set up a front-end HTTP server
Use apache, lighted, nginx, ha-proxy to handle the 80 port, start multiple instances from the back ends.
>start -Dhttp.port=9998
>start -Dhttp.port=9999

References:
http://sillycat.iteye.com/blog/1757098
http://www.playframework.org/documentation/2.0.4/Samples

http://www.playframework.org/documentation/2.0.4/Production

你可能感兴趣的:(playframework)