前提
- Mac OSX10
- 2016年1月24日時点でplayframework2.4でした。
play framework インストール
brewよりインストール
$ brew update
$ brew install play
↓エラーとなりました。参考元が古かったようです。
Error: No available formula with the name "play"
Play 2.3 replaces the play command with activator:
brew install typesafe-activator
You can read more about this change at:
https://www.playframework.com/documentation/2.3.x/Migration23
https://www.playframework.com/documentation/2.3.x/Highlights23
playはtypesafe-activatorに置き換わってるとのことなので下記を実行。
$ brew install typesafe-activator
==> Downloading https://downloads.typesafe.com/typesafe-activator/1.3.7/typesafe
######################################################################## 100.0%
🍺 /usr/local/Cellar/typesafe-activator/1.3.7: 4 files, 1.2M, built in 5 seconds
$ activator -h #ヘルプを出力
play framework のプロジェクト作成
activatorを利用してプロジェクトを作成します。
実行ディレクトリに作成プロジェクトが作成されるので任意の箇所に移動しておきます。
下記を実行し対話形式で作成を進める。
$ activator new
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
Enter a name for your application (just press enter for 'play-scala')
> playScalaExample
OK, application "playScalaExample" is being created using the "play-scala" template.
To run "playScalaExample" from the command line, "cd playScalaExample" then:
/usr/local/Cellar/typesafe-activator/1.3.7/playScalaExample/activator run
To run the test for "playScalaExample" from the command line, "cd playScalaExample" then:
/usr/local/Cellar/typesafe-activator/1.3.7/playScalaExample/activator test
To run the Activator UI for "playScalaExample" from the command line, "cd playScalaExample" then:
/usr/local/Cellar/typesafe-activator/1.3.7/playScalaExample/activator ui
6) play-scala
、プロジェクト名playScalaExample
で作成しました。
play framework の起動
下記コマンドで起動します。
$ cd playScalaExample/
$ activator run
Getting org.scala-sbt sbt 0.13.8 ...
downloading https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13.8/jars/sbt.jar ...
:
:
--- (Running the application, auto-reloading is enabled) ---
[info] p.c.s.NettyServer - 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...)
初回ダウンロードがあるため多少時間がかかるようでした。
ブラウザからアクセスします。
http://localhost:9000
無事表示されました!
eclipseに取り込む
取り込み準備
プロジェクトのディレクトリまで移動しておきます。
$ cd playScalaExample
$ activator eclipse
[error] Not a valid command: eclipse (similar: help, alias)
[error] Not a valid project ID: eclipse
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: eclipse (similar: deliver, licenses, clean)
[error] eclipse
[error]
エラーとなりました。。。既に解決方法も当サイトで投稿されておりましたので参考にさせて頂きました。
eclipseコマンドを利用できるようにするにはplugins.sbtの修正が必要とのことです。
vi project/plugins.sbt
↓最後に1行追加
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
viは:wqで保存。
バージョンは下記元より確認
https://github.com/typesafehub/sbteclipse
仕切りなおして再度実行
$ activator eclipse
eclipse取り込み
eclipseを起動
インポート>既存のプロジェクトをワークスペースへ>ルート・ディレクトリの選択に対象のプロジェクトを指定>完了
再度起動しブラウザ表示されることを確認。
$ activator run
eclipseからタイトルなどを変更、ビルドし反映されていることを確認して終了w
途中つまずきながらもeclipseでの開発環境もできたので、良かった。
activator UIとの違いについては別途確認しようと思う。