SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Tips and tricks for setting up a
Play 2 project
!
!

Manuel Bernhardt

#DV13PlayTricks

@elmanu
play new hello-play
Let’s get started

#DV13PlayTricks

@elmanu
Hello world - build.sbt
name := "hello-play"!
!

version := "1.0-SNAPSHOT"!
!

libraryDependencies ++= Seq(!
jdbc,!
anorm,!
cache!
)
!
!

play.Project.playScalaSettings!

#DV13PlayTricks

@elmanu
Hello world - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!

// The Typesafe repository !
resolvers += "Typesafe repository" at "http://
repo.typesafe.com/typesafe/releases/"!
!

// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")!

#DV13PlayTricks

@elmanu
First things first: Scalariform
!

Code indentation is good for your health

#DV13PlayTricks

@elmanu
Scalariform! - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!

// The Typesafe repository !
resolvers += "Typesafe repository" at "http://
repo.typesafe.com/typesafe/releases/"!
!

// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")!
!

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")!

#DV13PlayTricks

@elmanu
Scalariform! - build.sbt
name := "hello-play"!
!

version := "1.0-SNAPSHOT"!
!

libraryDependencies ++= Seq(cache)!
!

play.Project.playScalaSettings!
!

scalariformSettings

#DV13PlayTricks

@elmanu
#DV13PlayTricks

@elmanu
#DV13PlayTricks

@elmanu
Scalastyle
Keep it clean

#DV13PlayTricks

@elmanu
Scalastyle! - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!

// The Typesafe repository !
resolvers += "Typesafe repository" at "http://
repo.typesafe.com/typesafe/releases/"!
!

// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")!
!

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")!
!

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" %
"0.3.2")

#DV13PlayTricks

@elmanu
Scalastyle! - build.sbt
name := "hello-play"!
!

version := "1.0-SNAPSHOT"!
!

libraryDependencies ++= Seq(cache)!
!

play.Project.playScalaSettings!
!

scalariformSettings!
!

org.scalastyle.sbt.ScalastylePlugin.Settings

#DV13PlayTricks

@elmanu
Scalastyle! - scalastyle-config.xml
<scalastyle>!
<name>Scalastyle sample configuration</name>!
<check level=“warning”!
class=“org.scalastyle.file.FileLineLengthChecker"!
enabled="true">!
<parameters>!
<parameter name="maxLineLength"><![CDATA[100]]></parameter>!
<parameter name="tabSize"><![CDATA[2]]></parameter>!
</parameters>!
</check>!
</scalastyle>

#DV13PlayTricks

@elmanu
Scalastyle! - Output
<?xml version="1.0" encoding="US-ASCII"?>!
<checkstyle version=“5.0”>!
<file name=“/Users/manu/w/hello-play/app/controllers/Application.scala">!
<error line=“12"!
source=“org.scalastyle.file.FileLineLengthChecker"!
severity=“warning"!
message="File line length exceeds 100 characters”>!
</error>!
</file>!
</checkstyle>!

#DV13PlayTricks

@elmanu
Sub-projects
!

Keeping things fast

#DV13PlayTricks

@elmanu
Root

Module 1

Module 2

Core

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
Sub-projects - build.sbt
play.Project.playScalaSettings!
!
def playProject(name: String) = play.Project(!
name = name,!
path = file("modules/" + name)!
).!
settings(scalariformSettings :_*).!
settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)!
!
lazy val core = playProject("core")!
!
lazy val module1 = playProject("module1").dependsOn(core)!
!
lazy val module2 = playProject("module2").dependsOn(core)!
!
lazy val root = playProject("hello-play").in(file(".")).!
! !
dependsOn(module1, module2).!
aggregate(module1, module2)

#DV13PlayTricks

@elmanu
#DV13PlayTricks

@elmanu
application.conf

#DV13PlayTricks

@elmanu
routes

application.conf

module1.routes

module2.routes

#DV13PlayTricks

@elmanu
Snapshot dependencies and
multi-module projects
Workarounds

#DV13PlayTricks

@elmanu
Snapshot dependencies

• https://github.com/sbt/sbt/issues/413

#DV13PlayTricks

@elmanu
Snapshot dependencies

• https://github.com/sbt/sbt/issues/413

#DV13PlayTricks

@elmanu
Snapshot dependencies - workarounds

• Don’t use snapshot dependencies	

• Convince library authors to make releases	

• Use a cache, e.g. Squid	

•

OS X: http://squidman.net/squidman

-­‐Dhttp.proxyHost=localhost	
  -­‐Dhttp.proxyPort=8090

#DV13PlayTricks

@elmanu
Tools for Chrome
After all, we’re building web-applications

#DV13PlayTricks

@elmanu
https://chrome.google.com/webstore/detail/play-framework-tools/dchhggpgbommpcjpogaploblnpldbmen

#DV13PlayTricks

@elmanu
Play Auto Refresh - plugins.sbt
// Comment to get more information during initialization!
logLevel := Level.Warn!
!
// The Typesafe repository !
resolvers += "Typesafe repository" at "http://repo.typesafe.com/
typesafe/releases/"!
!
// Use the Play sbt plugin for Play projects!
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")!
!
addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")!
!
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2")!
!
addSbtPlugin("com.jamesward" %% "play-auto-refresh" % "0.0.7")

#DV13PlayTricks

@elmanu
Play Auto Refresh - build.sbt
name := "hello-play"!
!
version := "1.0-SNAPSHOT"!
!
libraryDependencies ++= Seq(!
jdbc,!
anorm,!
cache!
)
!
!
play.Project.playScalaSettings!
!
scalariformSettings!
!
org.scalastyle.sbt.ScalastylePlugin.Settings!
!
com.jamesward.play.BrowserNotifierPlugin.livereload

#DV13PlayTricks

@elmanu
Chrome

Your IDE

play ~ run
No more ⌘+R, yeah!
#DV13PlayTricks

@elmanu
Open errors in IDE

Click to open in editor

Instructions at https://github.com/jamesward/play-framework-chrome-tools
#DV13PlayTricks

@elmanu
Use dependency injection right
away
A poor man’s solution

#DV13PlayTricks

@elmanu
DI - Users controller
package controllers!
!

class Users(greeting: String) extends BaseController {!
!

def hello = Action { implicit request =>!
! Ok(greeting)!
}!
!

}

#DV13PlayTricks

@elmanu
DI - Routes

GET

#DV13PlayTricks

/users

@controllers.Users.hello!

@elmanu
DI - Global.scala
import controllers.Users!
import play.api.GlobalSettings!
!
object Global extends GlobalSettings {!
!
override def getControllerInstance[A](controllerClass: Class[A]): A = {!
!
val USERS = classOf[Users]!
!
val instance = controllerClass match {!
case USERS => new Users("Hello users")!
case _ => super.getControllerInstance(controllerClass)!
}!
!
instance.asInstanceOf[A]!
}!
}

#DV13PlayTricks

@elmanu
That’s it! Questions?
!
https://github.com/manuelbernhardt/hello-play-dv13
!
http://manuel.bernhardt.io

#DV13PlayTricks

@elmanu

Más contenido relacionado

La actualidad más candente

Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Jacob Kaplan-Moss
 
Theme Development and Customization
Theme Development and CustomizationTheme Development and Customization
Theme Development and CustomizationAniket Pant
 
Getting Started With Play Framework
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play FrameworkTreasury user10
 
HTML5: Building for a Faster Web
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster WebEric Bidelman
 
Puppet for Everybody: Federated and Hierarchical Puppet Enterprise
Puppet for Everybody: Federated and Hierarchical Puppet EnterprisePuppet for Everybody: Federated and Hierarchical Puppet Enterprise
Puppet for Everybody: Federated and Hierarchical Puppet EnterprisecbowlesUT
 

La actualidad más candente (6)

Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 
Theme Development and Customization
Theme Development and CustomizationTheme Development and Customization
Theme Development and Customization
 
Getting Started With Play Framework
Getting Started With Play FrameworkGetting Started With Play Framework
Getting Started With Play Framework
 
HTML5: Building for a Faster Web
HTML5: Building for a Faster WebHTML5: Building for a Faster Web
HTML5: Building for a Faster Web
 
Puppet for Everybody: Federated and Hierarchical Puppet Enterprise
Puppet for Everybody: Federated and Hierarchical Puppet EnterprisePuppet for Everybody: Federated and Hierarchical Puppet Enterprise
Puppet for Everybody: Federated and Hierarchical Puppet Enterprise
 

Similar a Tips and tricks for setting up a Play 2 project

Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
 
Iphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2Dcreagamers
 
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, PuppetPuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, PuppetPuppet
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with GradleAndres Almiray
 
Summit2014 topic 0153 - Alfresco Maven for shared properties
Summit2014 topic 0153 - Alfresco Maven for shared propertiesSummit2014 topic 0153 - Alfresco Maven for shared properties
Summit2014 topic 0153 - Alfresco Maven for shared propertiesAngel Borroy López
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteAllen Wittenauer
 
"I have a framework idea" - Repeat less, share more.
"I have a framework idea" - Repeat less, share more."I have a framework idea" - Repeat less, share more.
"I have a framework idea" - Repeat less, share more.Fabio Milano
 
Composer: putting dependencies on the score
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the scoreRafael Dohms
 
Advanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentAdvanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentMike Brittain
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Derek Willian Stavis
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 
Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameNick Pruehs
 
Acceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and seleniumAcceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and seleniumAsko Soukka
 
IzPack at LyonJUG'11
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11julien.ponge
 
Publishing a Perl6 Module
Publishing a Perl6 ModulePublishing a Perl6 Module
Publishing a Perl6 Moduleast_j
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 

Similar a Tips and tricks for setting up a Play 2 project (20)

Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 
Iphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2DIphone and Ipad development Game with Cocos2D
Iphone and Ipad development Game with Cocos2D
 
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, PuppetPuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
PuppetConf 2017: Puppet Tasks: Taming ssh in a "for" loop- Alex Dreyer, Puppet
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Phing
PhingPhing
Phing
 
Creating Better Builds with Gradle
Creating Better Builds with GradleCreating Better Builds with Gradle
Creating Better Builds with Gradle
 
Summit2014 topic 0153 - Alfresco Maven for shared properties
Summit2014 topic 0153 - Alfresco Maven for shared propertiesSummit2014 topic 0153 - Alfresco Maven for shared properties
Summit2014 topic 0153 - Alfresco Maven for shared properties
 
Apache Hadoop Shell Rewrite
Apache Hadoop Shell RewriteApache Hadoop Shell Rewrite
Apache Hadoop Shell Rewrite
 
"I have a framework idea" - Repeat less, share more.
"I have a framework idea" - Repeat less, share more."I have a framework idea" - Repeat less, share more.
"I have a framework idea" - Repeat less, share more.
 
Composer: putting dependencies on the score
Composer: putting dependencies on the scoreComposer: putting dependencies on the score
Composer: putting dependencies on the score
 
Advanced Topics in Continuous Deployment
Advanced Topics in Continuous DeploymentAdvanced Topics in Continuous Deployment
Advanced Topics in Continuous Deployment
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great Game
 
Acceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and seleniumAcceptance testing plone sites and add ons with robot framework and selenium
Acceptance testing plone sites and add ons with robot framework and selenium
 
IzPack at LyonJUG'11
IzPack at LyonJUG'11IzPack at LyonJUG'11
IzPack at LyonJUG'11
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
Publishing a Perl6 Module
Publishing a Perl6 ModulePublishing a Perl6 Module
Publishing a Perl6 Module
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 

Más de Manuel Bernhardt

Is there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgManuel Bernhardt
 
Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Manuel Bernhardt
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?Manuel Bernhardt
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?Manuel Bernhardt
 
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 20178 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017Manuel Bernhardt
 
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware ofScala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware ofManuel Bernhardt
 
8 Akka anti-patterns you'd better be aware of
8 Akka anti-patterns you'd better be aware of8 Akka anti-patterns you'd better be aware of
8 Akka anti-patterns you'd better be aware ofManuel Bernhardt
 
Beyond the buzzword: a reactive web-appliction in practice
Beyond the buzzword: a reactive web-appliction in practiceBeyond the buzzword: a reactive web-appliction in practice
Beyond the buzzword: a reactive web-appliction in practiceManuel Bernhardt
 
Beyond the Buzzword - a reactive application in practice
Beyond the Buzzword - a reactive application in practiceBeyond the Buzzword - a reactive application in practice
Beyond the Buzzword - a reactive application in practiceManuel Bernhardt
 
Six years of Scala and counting
Six years of Scala and countingSix years of Scala and counting
Six years of Scala and countingManuel Bernhardt
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015Manuel Bernhardt
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysManuel Bernhardt
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMManuel Bernhardt
 
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migrationBack to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migrationManuel Bernhardt
 
Project Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsProject Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsManuel Bernhardt
 

Más de Manuel Bernhardt (19)

Is there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems Hamburg
 
Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?
 
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 20178 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
8 akka anti-patterns you'd better be aware of - Reactive Summit Austin 2017
 
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware ofScala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
Scala Days Copenhagen - 8 Akka anti-patterns you'd better be aware of
 
8 Akka anti-patterns you'd better be aware of
8 Akka anti-patterns you'd better be aware of8 Akka anti-patterns you'd better be aware of
8 Akka anti-patterns you'd better be aware of
 
Beyond the buzzword: a reactive web-appliction in practice
Beyond the buzzword: a reactive web-appliction in practiceBeyond the buzzword: a reactive web-appliction in practice
Beyond the buzzword: a reactive web-appliction in practice
 
Beyond the Buzzword - a reactive application in practice
Beyond the Buzzword - a reactive application in practiceBeyond the Buzzword - a reactive application in practice
Beyond the Buzzword - a reactive application in practice
 
Six years of Scala and counting
Six years of Scala and countingSix years of Scala and counting
Six years of Scala and counting
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Writing a technical book
Writing a technical bookWriting a technical book
Writing a technical book
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migrationBack to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
 
Project Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsProject Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 months
 
Scala - Java2Days Sofia
Scala - Java2Days SofiaScala - Java2Days Sofia
Scala - Java2Days Sofia
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala pitfalls
Scala pitfallsScala pitfalls
Scala pitfalls
 

Último

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Tips and tricks for setting up a Play 2 project

  • 1. Tips and tricks for setting up a Play 2 project ! ! Manuel Bernhardt #DV13PlayTricks @elmanu
  • 2. play new hello-play Let’s get started #DV13PlayTricks @elmanu
  • 3. Hello world - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(! jdbc,! anorm,! cache! ) ! ! play.Project.playScalaSettings! #DV13PlayTricks @elmanu
  • 4. Hello world - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http:// repo.typesafe.com/typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1")! #DV13PlayTricks @elmanu
  • 5. First things first: Scalariform ! Code indentation is good for your health #DV13PlayTricks @elmanu
  • 6. Scalariform! - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http:// repo.typesafe.com/typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")! ! addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")! #DV13PlayTricks @elmanu
  • 7. Scalariform! - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(cache)! ! play.Project.playScalaSettings! ! scalariformSettings #DV13PlayTricks @elmanu
  • 11. Scalastyle! - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http:// repo.typesafe.com/typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")! ! addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")! ! addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2") #DV13PlayTricks @elmanu
  • 12. Scalastyle! - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(cache)! ! play.Project.playScalaSettings! ! scalariformSettings! ! org.scalastyle.sbt.ScalastylePlugin.Settings #DV13PlayTricks @elmanu
  • 13. Scalastyle! - scalastyle-config.xml <scalastyle>! <name>Scalastyle sample configuration</name>! <check level=“warning”! class=“org.scalastyle.file.FileLineLengthChecker"! enabled="true">! <parameters>! <parameter name="maxLineLength"><![CDATA[100]]></parameter>! <parameter name="tabSize"><![CDATA[2]]></parameter>! </parameters>! </check>! </scalastyle> #DV13PlayTricks @elmanu
  • 14. Scalastyle! - Output <?xml version="1.0" encoding="US-ASCII"?>! <checkstyle version=“5.0”>! <file name=“/Users/manu/w/hello-play/app/controllers/Application.scala">! <error line=“12"! source=“org.scalastyle.file.FileLineLengthChecker"! severity=“warning"! message="File line length exceeds 100 characters”>! </error>! </file>! </checkstyle>! #DV13PlayTricks @elmanu
  • 17. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 18. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 19. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 20. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 21. Sub-projects - build.sbt play.Project.playScalaSettings! ! def playProject(name: String) = play.Project(! name = name,! path = file("modules/" + name)! ).! settings(scalariformSettings :_*).! settings(org.scalastyle.sbt.ScalastylePlugin.Settings :_*)! ! lazy val core = playProject("core")! ! lazy val module1 = playProject("module1").dependsOn(core)! ! lazy val module2 = playProject("module2").dependsOn(core)! ! lazy val root = playProject("hello-play").in(file(".")).! ! ! dependsOn(module1, module2).! aggregate(module1, module2) #DV13PlayTricks @elmanu
  • 25. Snapshot dependencies and multi-module projects Workarounds #DV13PlayTricks @elmanu
  • 28. Snapshot dependencies - workarounds • Don’t use snapshot dependencies • Convince library authors to make releases • Use a cache, e.g. Squid • OS X: http://squidman.net/squidman -­‐Dhttp.proxyHost=localhost  -­‐Dhttp.proxyPort=8090 #DV13PlayTricks @elmanu
  • 29. Tools for Chrome After all, we’re building web-applications #DV13PlayTricks @elmanu
  • 31. Play Auto Refresh - plugins.sbt // Comment to get more information during initialization! logLevel := Level.Warn! ! // The Typesafe repository ! resolvers += "Typesafe repository" at "http://repo.typesafe.com/ typesafe/releases/"! ! // Use the Play sbt plugin for Play projects! addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")! ! addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")! ! addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.3.2")! ! addSbtPlugin("com.jamesward" %% "play-auto-refresh" % "0.0.7") #DV13PlayTricks @elmanu
  • 32. Play Auto Refresh - build.sbt name := "hello-play"! ! version := "1.0-SNAPSHOT"! ! libraryDependencies ++= Seq(! jdbc,! anorm,! cache! ) ! ! play.Project.playScalaSettings! ! scalariformSettings! ! org.scalastyle.sbt.ScalastylePlugin.Settings! ! com.jamesward.play.BrowserNotifierPlugin.livereload #DV13PlayTricks @elmanu
  • 33. Chrome Your IDE play ~ run No more ⌘+R, yeah! #DV13PlayTricks @elmanu
  • 34. Open errors in IDE Click to open in editor Instructions at https://github.com/jamesward/play-framework-chrome-tools #DV13PlayTricks @elmanu
  • 35. Use dependency injection right away A poor man’s solution #DV13PlayTricks @elmanu
  • 36. DI - Users controller package controllers! ! class Users(greeting: String) extends BaseController {! ! def hello = Action { implicit request =>! ! Ok(greeting)! }! ! } #DV13PlayTricks @elmanu
  • 38. DI - Global.scala import controllers.Users! import play.api.GlobalSettings! ! object Global extends GlobalSettings {! ! override def getControllerInstance[A](controllerClass: Class[A]): A = {! ! val USERS = classOf[Users]! ! val instance = controllerClass match {! case USERS => new Users("Hello users")! case _ => super.getControllerInstance(controllerClass)! }! ! instance.asInstanceOf[A]! }! } #DV13PlayTricks @elmanu