作業メモ兼ねてます。
前提
- JDK 1.8 をインストール
- homebrew で scala と sbt をインストール
homebrew でインストール
$ brew install typesafe-activator
$ which activator
/usr/local/bin/activator
アプリケーション作成
$ activator new my-first-app play-scala
いろいろ表示されるが次が表示されたらおしまい
Fetching the latest list of templates...
OK, application "my-first-app" is being created using the "play-scala" template.
To run "my-first-app" from the command line, "cd my-first-app" then:
/Users/user/my-first-app/activator runTo run the test for "my-first-app" from the command line, "cd my-first-app" then:
/Users/user/my-first-app/activator testTo run the Activator UI for "my-first-app" from the command line, "cd my-first-app" then:
/Users/user/my-first-app/activator ui
Activator コンソールに入る
$ cd my-first-app
$ activator
またもやいろいろ表示されるが次が表示されたら、コンソールに入れている。
[my-first-app] $
アプリケーション実行
[my-first-app] $ run
--- (Running the application, auto-reloading is enabled) ---
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Ctrl+D to stop and go back to the console...)
REPLの実行
[my-first-app] $ console
scala>
ファイル
ファイル | 内容 |
---|---|
conf/application.conf | 設定ファイル |
conf/routes | ルーティングファイル |
app/controllers | コントローラ |
app/views | ビュー |
ディレクトリレイアウト
Rails に似ている
my-first-app/
├── LICENSE
├── README
├── activator
├── activator-launch-1.2.12.jar
├── app
│ ├── assets
│ ├── controllers
│ │ └── Application.scala
│ └── views
│ ├── index.scala.html
│ └── main.scala.html
├── build.sbt
├── conf
│ ├── application.conf
│ └── routes
├── logs
│ └── application.log
├── project
│ ├── build.properties
│ ├── plugins.sbt
│ ├── project
│ │ └── target
│ └── target
│ ├── coffeescript
│ ├── config-classes
│ ├── jshint
│ ├── less
│ ├── node-modules
│ ├── resolution-cache
│ ├── scala-2.10
│ ├── streams
│ └── webjars-plugin.cache
├── public
│ ├── images
│ │ └── favicon.png
│ ├── javascripts
│ │ └── hello.js
│ └── stylesheets
│ └── main.css
├── target
│ ├── native_libraries
│ │ ├── 32bits
│ │ └── 64bits
│ ├── resolution-cache
│ │ ├── my-first-app
│ │ └── reports
│ ├── scala-2.11
│ │ ├── cache
│ │ ├── classes
│ │ ├── classes_managed
│ │ ├── src_managed
│ │ └── twirl
│ ├── streams
│ │ ├── $global
│ │ ├── compile
│ │ ├── runtime
│ │ └── web-assets
│ └── web
│ └── public
└── test
├── ApplicationSpec.scala
└── IntegrationSpec.scala
43 directories, 19 files
mysqlの設定
JDBCを使う。
はじめにデータベースを作っておく。
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/play_scala_app"
db.default.user=bibio
db.default.password=""
db.default.logStatements=true
activator run で実行するとエラー
play.api.Configuration$$anon$1: Configuration error[Driver not found: [com.mysql.jdbc.Driver]]
以下を追加
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.34"
再度activator run
IntelliJ IDEA 14 へインポートする
- IntelliJ IDEA > Import Project
- Import Project from external model > SBT を選択して [Next]クリック
- [Finish]クリック
実行する
- ツールバー Run > Run
- Edit Configuration > + > Play2 App
- [Run]クリック
activator
activator
カレントディレクトリがプロジェクト内にあればロードされ、シェルが起動する
プロジェクトが読み込めなければヘルプが表示される。activator ui
UI(ブラウザ)でプロジェクトを開く。プロジェクトがなければプロジェクト作成画面を開く。activator new [project-name] [template-name]
新規コマンドを作成する。プロジェクト名がなければプロジェクト入力プロンプトが、
テンプレートが指定されなければテンプレート選択が表示されるactivator list-templates
最新のテンプレートを取得し、一覧を表示する。