Scala

Install

Mac OS X & Homebrew

play frameworkは以下のコマンド一発で入る。便利。

$ brew install typesafe-activator

Linux (Ubuntu 14.04 LTS)

WIP

create new project

$ activator new (projectname)

`Fetching the latest list of templates...

Browse the list of templates: http://typesafe.com/activator/templates
Choose from these featured templates or enter a template name:
  1) minimal-akka-java-seed
  2) minimal-akka-scala-seed
  3) minimal-java
  4) minimal-scala
  5) play-java
  6) play-scala
(hit tab to see a list of all templates)
> 6
OK, application "(projectname)" is being created using the "play-scala" template.

(projectname)のところで指定したディレクトリが作成されるのでcdする。そしておもむろに立ち上げてみる。

$ activator run

http://localhost:9000/ にアクセスするとおもむろにコンパイルがはじまり、終わると「Welcome to play」のサンプルページが現れる。activator runは立ち上げたまま次のステップへ進んで良い(ファイルが更新されたら自動で再コンパイルが走る)

Hello World

http://qiita.com/kukita/items/6326f1439abec013a479

ここの手順 1-9(Applicaton.scala編集)を行い、ブラウザをリロードすると再コンパイルが始まって"Hello, World."という文字列が表示される。

DBとの接続

とりあえずbuild.sbtをいじる。

※ケツカンマに気をつけろ!!!!!

参考資料

PlayFramework - (60分クッキング) Play Framework (Scala)+MySQLでREST APIサーバーを作る - Qiita

Play 2.4 Hands on

導入部分はわかりやすかった

感想

  • "activator new play2-hands-on" が完了した時点で.gitignoreが自動的に作成されているので、この時点GitHubのでリポジトリ作成しちゃってよさそう。
  • build.sbtを編集するときはケツカンマに注意だ!間違えるとこうなるぞ!
[error] [/Users/karia/source/karia/scala-play-sample/build.sbt]:16: ')' expected but string literal found.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
  • 初回のactivator runは数十分単位で時間かかる(猛然とダウンロード祭りが始まる)
  • HTTPのリクエストが来てからScalaのcompileをはじめる、ヤバい
[info] Compiling 7 Scala sources and 1 Java source to /Users/karia/source/karia/scala-play-sample/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.6. Compiling...
[info]   Compilation completed in 14.1 s
Warning: node.js detection failed, sbt will use the Rhino based Trireme JavaScript engine instead to run JavaScript assets compilation, which in some cases may be orders of magnitude slower than using node.js.
[info] - play.api.Play - Application started (Dev)
  • 2015/11/27時点でのバージョン
Play 2.4.4
scala 2.11.6

リロード   新規 下位ページ作成 編集 凍結 差分 添付 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS